subtackting dates

papercut19

Newcomer
Joined
Mar 22, 2006
Messages
1
hy everyone,

i working on a site wher i have 2 calculate the days that someone has on the event.

the meaning is that i get 2 dates form the database. No problem so far. But then i have 2 substrackt the 2 dates. I got this 2 but i have 31 days in each month
so the diffrence between 03/07/2006 and 29/06/2006 gives 5 and it should be 4.

My code is : var datum1 = new Date(2006, 06, 29);
var datum2 = new Date(2006, 07, 03);
var DiffADate = Math.round((datum2 - datum1)/864e5);
 
I'm not sure what language you're using - is that Javascript?
In .NET, you'd use the Subtract method of a DateTime variable to get a TimeSpan object, as in:
C#:
DateTime d1 = new DateTime(2006, 06, 29);
DateTime d2 = new DateTime(2006, 07, 03);
TimeSpan ts = d1.Subtract(d2);

Then you could check ts.Days, for example, to get -4. Or change it to "d2.Subtract(d1);" to get 4.

-nerseus
 
Back
Top