JavaScript equivalent of DateDiff

Results 1 to 3 of 3

Thread: JavaScript equivalent of DateDiff

  1. #1
    Join Date
    Dec 1969

    Default JavaScript equivalent of DateDiff

    Hi,<BR>Does anyone know of the JavaScript equivalent of DateDiff? <BR>I have to check that a date is between a start and end date range, and a normal &#060;= or &#062;= doesn&#039;t work, also tried using Date.parse, but this doesn&#039;t seem to be consistent, ie 10/6/2001 is less than 1/6/2001!! <BR>Oh by the way, this is European formatting (DD/MM/YYYY), so am I going to have to convert all dates to American format, re-convert for displaying on screen to get this to work?<BR>Thanks for any help,<BR>Bob

  2. #2
    Join Date
    Dec 1969

    Default Kind of...

    Kind of, it&#039;s a bit longer winded though. You can get around American (annoying) and British/French (normal) [waiting for flames!] formats by specifically setting the year, month and date separately as below.<BR><BR>==== START<BR>// Date.UTC Finds the number of seconds elapsed<BR>// between Midnight Jan 1 1970 and the time specified.<BR><BR>// Change according to values:<BR>var StartDate = new Date(Date.UTC(year, month, day));<BR><BR>// Change according to values:<BR>var EndDate = new Date(Date.UTC(year, month, day));<BR><BR>// You can now use EndDate - StartDate to find<BR>// the number of seconds between the two.<BR>// Then divide by 60 for minutes, then 60 for hours...<BR>// You get the picture.<BR><BR>==== END<BR><BR>Craig.

  3. #3
    Darren Neimke Guest

    Default Work In Progress

    Bob,<BR><BR>I&#039;ve just uploaded some code that I&#039;m currently working on for a future article. You can see it here...<BR><BR><BR><BR>It has no explanation of how it works yet, but I should have the text written by tommorrow. Have a play around with it and if you have any problems understanding how it works wait until I&#039;ve uploaded the accompanying text. Then if you still have problems - e-mail me at....<BR><BR><BR><BR>HTH<BR><BR>Darren Neimke<BR>[ ]<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts