chintansshah Posted November 10, 2010 Share Posted November 10, 2010 var date1 = new Date("18/09/2010"); var date2 = new Date("01/10/2010"); var date1Comp = date1.getTime(); // milliseconds var date2Comp = date2.getTime(); if (date1Comp < date2Comp) { alert("From date is earlier than To date."); return false; } If I used above code to compare then it give me wrong result,. Can anybody help, it's very urgent. Link to comment https://forums.phpfreaks.com/topic/218264-date-compare-urgent/ Share on other sites More sharing options...
salathe Posted November 10, 2010 Share Posted November 10, 2010 JavaScript's Date object does not accept that format of date. Either use a format that it can use, or preferably use one of either a millisecond timestamp or individual date-part arguments (new Date(year, month, date)). Link to comment https://forums.phpfreaks.com/topic/218264-date-compare-urgent/#findComment-1132552 Share on other sites More sharing options...
chintansshah Posted November 10, 2010 Author Share Posted November 10, 2010 Can you give me a Code to compare dates? Link to comment https://forums.phpfreaks.com/topic/218264-date-compare-urgent/#findComment-1132553 Share on other sites More sharing options...
Adam Posted November 10, 2010 Share Posted November 10, 2010 As salathe said, you cannot pass a string in that format to the JavaScript object. Try: var date1 = new Date(2010, 9, 18); var date2 = new Date(2010, 10, 1); Link to comment https://forums.phpfreaks.com/topic/218264-date-compare-urgent/#findComment-1132558 Share on other sites More sharing options...
chintansshah Posted November 11, 2010 Author Share Posted November 11, 2010 Thanks MRAdam, it works now Link to comment https://forums.phpfreaks.com/topic/218264-date-compare-urgent/#findComment-1133156 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.