Thanks Jake, 'took me abt 5 minutes after I read the article to modify your
function to work with yyyy-mm-dd, could probably have been done a little more
dynamically and compact, but I am a little pressed for time, so maybe later...
paste my code here so you can have a laugh...
regards
Ib
function dateComponents(dateStr, format) {
var results = new Array();
var datePat = /^(\d{2}|\d{4})(\/|-|\.)(\d{1,2})\2(\d{2}|\d{4})$/;
var matchArray = dateStr.match(datePat);
if (matchArray == null) {
return null;
}
// parse date into variables
if (format.charAt(0)=="d"){ //what format does the server use for
dates?
results[0] = matchArray[1];
results[1] = matchArray[3];
results[2] = matchArray[4];
//check for two digit (20th century) years and prepend 19. - should
probably be a check to se if year is between 2000 and 2050 or so....
matchArray[4] = (matchArray[4].length == 2) ? '19' + matchArray[4] :
matchArray[4];
} else if (format.charAt(0)=="m"){
results[0] = matchArray[3];
results[1] = matchArray[1];
results[2] = matchArray[4];
//check for two digit (20th century) years and prepend 19. - should
probably be a check to se if year is between 2000 and 2050 or so....
matchArray[4] = (matchArray[4].length == 2) ? '19' + matchArray[4] :
matchArray[4];
} else if (format.charAt(0)=="y"){
results[0] = matchArray[4];
results[1] = matchArray[3];
results[2] = matchArray[1];
//check for two digit (20th century) years and prepend 19. - should
probably be a check to se if year is between 2000 and 2050 or so....
matchArray[1] = (matchArray[1].length == 2) ? '19' + matchArray[1] :
matchArray[1];
}
return results;
}
Thanks Jake, 'took me abt 5 minutes after I read the article to modify your function to work with yyyy-mm-dd, could probably have been done a little more dynamically and compact, but I am a little pressed for time, so maybe later...
paste my code here so you can have a laugh...
regards Ib
function dateComponents(dateStr, format) { var results = new Array(); var datePat = /^(\d{2}|\d{4})(\/|-|\.)(\d{1,2})\2(\d{2}|\d{4})$/; var matchArray = dateStr.match(datePat); if (matchArray == null) { return null; } // parse date into variables if (format.charAt(0)=="d"){ //what format does the server use for dates? results[0] = matchArray[1]; results[1] = matchArray[3]; results[2] = matchArray[4]; //check for two digit (20th century) years and prepend 19. - should probably be a check to se if year is between 2000 and 2050 or so.... matchArray[4] = (matchArray[4].length == 2) ? '19' + matchArray[4] : matchArray[4]; } else if (format.charAt(0)=="m"){ results[0] = matchArray[3]; results[1] = matchArray[1]; results[2] = matchArray[4]; //check for two digit (20th century) years and prepend 19. - should probably be a check to se if year is between 2000 and 2050 or so.... matchArray[4] = (matchArray[4].length == 2) ? '19' + matchArray[4] : matchArray[4]; } else if (format.charAt(0)=="y"){ results[0] = matchArray[4]; results[1] = matchArray[3]; results[2] = matchArray[1]; //check for two digit (20th century) years and prepend 19. - should probably be a check to se if year is between 2000 and 2050 or so.... matchArray[1] = (matchArray[1].length == 2) ? '19' + matchArray[1] : matchArray[1]; } return results; }