Dupdroid
Posts: 0
Joined: Sat Mar 30, 2013 9:07 pm

Invalid Date using new Date(_createdAt...

I keep getting "Invalid Date" error when passing _createdAt to the function. Please help.

function calcAge(dateString) {
var birthday = new Date(dateString + " PDT");
//var birthday = new Date(dateString);
alert(birthday);
return ...
}

Regards

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Invalid Date using new Date(_createdAt...

Hi,

Try this code:
codefunction calcAge(dateString) {
var birthday = new Date(dateString);
alert(birthday);
return ...
} /code
The server sends string that is properly parsed by embedded Date.

Dupdroid
Posts: 0
Joined: Sat Mar 30, 2013 9:07 pm

Invalid Date using new Date(_createdAt...

I have tried that already and that also didn't work.

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Invalid Date using new Date(_createdAt...

What do you see on the alert? codealert( dateString );/code

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Invalid Date using new Date(_createdAt...

What is the value of _createdAt?

Dupdroid
Posts: 0
Joined: Sat Mar 30, 2013 9:07 pm

Invalid Date using new Date(_createdAt...

Sorry for the delay. The output of alert(dateString) = 2013-03-29 16:06:34.517

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Invalid Date using new Date(_createdAt...

Could you call this?
codealert( typeof dateString );/code
Also try replacing the function with the following:
codefunction calcAge(dateString) {
var birthday = new Date( dateString + " " );
alert(birthday);
return ...
}/code

Dupdroid
Posts: 0
Joined: Sat Mar 30, 2013 9:07 pm

Invalid Date using new Date(_createdAt...

alert( typeof dateString ); = string
alert(birthday); = Invalid date

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Invalid Date using new Date(_createdAt...

We'll look for a solution.

Dupdroid
Posts: 0
Joined: Sat Mar 30, 2013 9:07 pm

Invalid Date using new Date(_createdAt...

A workaround is to only use the date and ignoring the time ie.

new Date(dateString.split(" ")[0]);

Return to “Issues”