I am trying to make a function which are supposed to check if a certain date is in the correct format. Do to this, the function takes in a variable, and breaks it down to three subvariables, year, month, and day. Later on I want to check each of these substrings against in a few if-statements.
When i run this with my GFs number which is 880413 then year=88, month=4, day=13 However, when I run this function with my own number which is 820922, then the function sets year to 82, month to 0?! and day=22.
How is this possibe? when month is 04, it cuts it off and shows only 4, but when month is 09 it cuts it off to 0.
Heres relevant code:
function isValidDate(date)
{
var valid = true;
var year = parseInt(date.substring(0, 2));
var month = parseInt(date.substring(2, 4)); // error here!
var day = parseInt(date.substring(4, 6));
alert(year+"--"+month+"--"+day+"--")
}
Heres output when running number 820922 (forget about the last 4 digits, they are for swedish social security number and do no need to be considered in this example)
And heres output with number 880413 (again forget about the last 4 digits)