Difference between integers (Dates)

  • Thread starter Thread starter ApeX
  • Start date Start date
A

ApeX

hi guys!
So here i have two arraylists with the following structure (year,
month, day)...
What's the best way to calculate difference between the two?

Example

arraylist1 - 12y, 1m, 10d
arraylist2 - 11y, 1m, 29d

....i need to get a new arraylist with values (1y, 1m, 12d)

Thnx!
 
DateTime a = new DateTime(2008, 10, 21);
DateTime b = new DateTime(2007, 1, 7);
TimeSpan elapsed = a - b;

TimeSpan has various properties for extracting the number of days etc.
 
hi,
Using a fiscal year:
arraylist1 - 12y, 1m, 10d = 12 * 360 + 1 * 30 + 10
arraylist2 - 11y, 1m, 29d = 11 * 360 + 1 * 30 + 29
...i need to get a new arraylist with values (1y, 1m, 12d)
(12 * 360 + 1 * 30 + 10) - (11 * 360 + 1 * 30 + 29) = 4360 - 4019 = 341
=> 0y + 11m + 11d


mfG
--> stefan <--
 
ApeX said:
hi guys!
So here i have two arraylists with the following structure (year,
month, day)...
What's the best way to calculate difference between the two?

Example

arraylist1 - 12y, 1m, 10d
arraylist2 - 11y, 1m, 29d

...i need to get a new arraylist with values (1y, 1m, 12d)

You can't, unless you have some way of knowing how many days are in the
respective months and also which of the years are leap years. (I.e., how many
total days are represented by each arraylist.) You really should start with
DateTime structs and use DateTime.Subtract() to generate a TimeSpan difference.

HTH,
-rick-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top