papercut19 Posted March 22, 2006 Posted March 22, 2006 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); Quote
*Experts* Nerseus Posted March 22, 2006 *Experts* Posted March 22, 2006 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: 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 Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.