Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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);

  • *Experts*
Posted

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

"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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...