I have wanged this parsedate function from a script, cargo cult style - woot!!!!
anyhow, I would like to tidy it up as it allows 212 as a year as well as 19234 as a year, now technically there can be these years, but not in my life time!!!! , so what's the best way to force 4 digit year?
I've highlighted the bit i beleive needs changing but not to sure what to change as I'm a little confused to what they are doing in the first place![Smile :) :)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
also is there an easy way in JS to do a date compare so i can check that one date is not prior to another entered?
many thanks.
"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
Code:
// Parse Date Function
function parseDate(value) {
if ((typeof value == "object") && (value.constructor == Date)) {
return value;
}
value += ""; // Force conversion to string
var date = NaN;
var dateArray = value.split("/");
if (dateArray.length != 3) {
dateArray = value.split("-");
}
if (dateArray.length == 3) {
var month = parseInt(dateArray[1]);
var day = parseInt(dateArray[0]);
var year = parseInt(dateArray[2]);
[b] // Rolling Y2K compliance:
if (year < 100) {
// Add current century to any 2-digit year
var today = new Date();
var todayYear = today.getFullYear();
var century = parseInt(todayYear / 100);
year = 100 * century + year;
// If more than 30 years in future, subtract a century
if ((year - todayYear) > 30) {
year = year - 100;
}
// If more than 70 years in the past, add a century
if ((todayYear - year) > 70) {
year = year + 100;
}
}[/b]
if (!(isNaN(day) || isNaN(month) || isNaN(year))) {
date = new Date(year, month-1, day);
// Verify that day, month and year are the same
// as their original values:
var newMonth = date.getMonth()+1;
var newDay = date.getDate();
var newYear = date.getFullYear();
if ( (newYear != year) || (newMonth != month) ||
(newDay != day) ) {
date = NaN;
}
}
}
return date;
}
anyhow, I would like to tidy it up as it allows 212 as a year as well as 19234 as a year, now technically there can be these years, but not in my life time!!!! , so what's the best way to force 4 digit year?
I've highlighted the bit i beleive needs changing but not to sure what to change as I'm a little confused to what they are doing in the first place
also is there an easy way in JS to do a date compare so i can check that one date is not prior to another entered?
many thanks.
"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.