Convert Returned String (YYYYMMDD) to Date

Use the substring method and substring off 4 elements and assign it to your new date for the year. Then substring off two elements at a time and store the month and date accordingly.

var dateString  = "20120515";
var year        = dateString.substring(0,4);
var month       = dateString.substring(4,6);
var day         = dateString.substring(6,8);

var date        = new Date(year, month-1, day);
var currentDate = new Date();

Now you can compare the two dates with the normal operators.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)