Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

Search the archives!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Javascript] Compare two dates


  • From: pp.koch at gmail.com (Peter-Paul Koch)
  • Subject: [Javascript] Compare two dates
  • Date: Fri Oct 14 10:27:12 2005

> Hello everybody,
>
> i would like to validate/compare two dates. The first date should be earlier
> than the second one.
>
> Have you an idea?

By far the easiest way: make both dates milliseconds and compare them.
Milliseconds are the only simple way of comparing dates.

var date1 = new Date(whatever);
var date2 = new Date(whatever);

var date1Comp = date1.getTime(); // milliseconds
var date2Comp = date2.getTime();

if (date1Comp < date2Comp)
{
  // date 1 is earlier than date 2
}

--
-------------------------------------------------------------------
ppk, freelance web developer
http://www.quirksmode.org/
------------------------------------------------------------------