Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
184
rated 0 times [  185] [ 1]  / answers: 1 / hits: 16918  / 14 Years ago, wed, august 18, 2010, 12:00:00

I have two dates 18-Aug-2010 and 19-Aug-2010 of this format. How to find whether which date is greater?


More From » validation

 Answers
3

You will need to create a custom parsing function to handle the format you want, and get date objects to compare, for example:



function customParse(str) {
var months = ['Jan','Feb','Mar','Apr','May','Jun',
'Jul','Aug','Sep','Oct','Nov','Dec'],
n = months.length, re = /(d{2})-([a-z]{3})-(d{4})/i, matches;

while(n--) { months[months[n]]=n; } // map month names to their index :)

matches = str.match(re); // extract date parts from string

return new Date(matches[3], months[matches[2]], matches[1]);
}

customParse(18-Aug-2010);
// Wed Aug 18 2010 00:00:00

customParse(19-Aug-2010) > customParse(18-Aug-2010);
// true

[#95881] Monday, August 16, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
carlton

Total Points: 373
Total Questions: 123
Total Answers: 97

Location: Saint Helena
Member since Wed, Nov 9, 2022
2 Years ago
;