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/
------------------------------------------------------------------
- References:
- [Javascript] Compare two dates
- From: OIivier Grossmann
- [Javascript] Compare two dates
- Prev by Date: [Javascript] Compare two dates
- Next by Date: [Javascript] Setting the size/width of a select control.
- Previous by thread: [Javascript] Compare two dates
- Next by thread: [Javascript] Setting the size/width of a select control.
- Index(es):