Date Difference

Results 1 to 2 of 2

Thread: Date Difference

  1. #1
    Join Date
    Dec 1969

    Default Date Difference

    Hi,<BR> Does any body know how to get the differenec between two dates using JavaScript.<BR><BR>Regards,<BR>Vikki

  2. #2
    Join Date
    Dec 1969

    Default RE: Date Difference in JavaScript!

    The only easy way to do it in JavaScript (and it&#039s not all that easy) is to convert each of the dates to milliseconds since 1/1/1970, which you can do with the getTime (or UTC or parse) method of Date. Subtract the two millisecond numbers from each other and divide by the appropriate value (e.g., 1000 for seconds, 60000 for minutes, 3600000 for hours) to get the number of seconds, minutes, hours or whatever between the two dates.<BR><BR>SO:<BR><BR>t1 = Date.parse("6/24/1992");<BR>t2 = (new Date()).getTime(); // current date and time<BR>milliDiff = t2 - t1; // diff in milliseconds<BR>daysDiff = milliDiff / ( 1000 * 60 * 60 * 24 ); // diff in days<BR><BR>BUT...<BR><BR>If one of the dates is prior to 1/1/1970, then you are hosed. You&#039ll have to write your own routine, from scratch. If you need help doing that, ask again.

Posting Permissions

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