Slim
Slim

Reputation: 1744

Strange date parsing issue

I'm loading some dates comming from my database into a HTML table in a string format. The string looks like 31-AUG-13 I'm parsing this string into a date object using the below code:

var paymentDate = $(this).find('td.paymentDate').text();
var test = $.datepicker.parseDate('d-M-y', paymentDate);

Everything is ok so far and I'm getting this date object: Date {Sat Aug 31 2013 00:00:00 GMT+0300 (FLE Standard Time)} But once the year is bigger than 2023. In my case 31-JAN-24 and so on it is turning to 1924 and not 2024, so I'm getting these date objects:

Date {Thu Jan 31 1924 00:00:00 GMT+0200 (FLE Daylight Time)}
Date {Fri Feb 29 1924 00:00:00 GMT+0200 (FLE Daylight Time)}
Date {Mon Mar 31 1924 00:00:00 GMT+0300 (FLE Standard Time)}
Date {Wed Apr 30 1924 00:00:00 GMT+0300 (FLE Standard Time)}

And so on. My question is regarding this strange issue. Is there a way to declare the year range and why it is going back to 1900 in the case when the year is bigger than 2023?

Upvotes: 1

Views: 227

Answers (1)

Dev
Dev

Reputation: 6786

This teaches a lesson always use year in full format same was case with y2k problem. Convert date from database in to yyyy format then use it.

Upvotes: 1

Related Questions