One way is to directly compare date objects. Choose an arbitrary year, month and day, and then include your time as follows:
var older = new Date("1980-01-01 12:15"); var newer = new Date("1980-01-01 12:30"); if (newer > older){ alert("Newer time is newer"); } else { alert ("The time is not newer"); }
The MDC documentation on a Date object will help with some details. The bottom line is that if you want to compare time, you actually do not need to call any methods on objects, and you can directly compare them. The date () object can take various lines to set a new time for the returned instance, this is from the MDC documentation:
today = new Date(); birthday = new Date("December 17, 1995 03:24:00"); birthday = new Date(1995,11,17); birthday = new Date(1995,11,17,3,24,0);
As you can see, this is pretty simple. Do not complicate or review the documentation :)
While here, run the test using your example:
var base = new Date("1980-01-01 9:30"); var test = new Date("1980-01-01 9:30:01"); if (test >= base){ alert("test time is newer or equal to base time"); } else { alert ("test time is older than 9.30"); }
dmp
source share