javascript - jQuery/JS - How to compare two date/time stamps? -


i have 2 date/time stamps:

d1 = 2011-03-02t15:30:18-08:00  d2 = 2011-03-02t15:36:05-08:00 

i want above compare two:

if (new date(d1) < new date(d2)) {alert('newer')} 

but not appear working correctly. there way compare not dates times well.? thanks

update:

console.log(d1 + ' ' + d2); console.log(new date(d1) > new date(d2))   2011-03-02t15:30:18-08:00 2011-03-02t15:36:05-08:00 false 2011-03-02t15:30:18-08:00 2011-03-02t15:30:18-08:00 false 2011-03-02t15:30:18-08:00 2011-03-02t14:15:04-08:00 false 

your timestamps should strings.

var d1 = "2011-03-02t15:30:18-08:00"; var d2 = "2011-03-02t15:36:05-08:00";  if (new date(d1) < new date(d2)) {alert('newer')} 

example: http://jsfiddle.net/hkpkf/


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -