Page 1 of 1

Invalid Date using new Date(_createdAt...

Posted: Tue Jun 04, 2013 7:36 pm
by Dupdroid

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


Invalid Date using new Date(_createdAt...

Posted: Tue Jun 04, 2013 8:00 pm
by Kateryna Grynko

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.


Invalid Date using new Date(_createdAt...

Posted: Tue Jun 04, 2013 8:17 pm
by Dupdroid

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


Invalid Date using new Date(_createdAt...

Posted: Tue Jun 04, 2013 8:22 pm
by Kateryna Grynko

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


Invalid Date using new Date(_createdAt...

Posted: Tue Jun 04, 2013 11:27 pm
by maxkatz

What is the value of _createdAt?


Invalid Date using new Date(_createdAt...

Posted: Wed Jun 05, 2013 7:41 pm
by Dupdroid

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


Invalid Date using new Date(_createdAt...

Posted: Wed Jun 05, 2013 7:50 pm
by Kateryna Grynko

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


Invalid Date using new Date(_createdAt...

Posted: Wed Jun 05, 2013 7:58 pm
by Dupdroid

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


Invalid Date using new Date(_createdAt...

Posted: Wed Jun 05, 2013 8:17 pm
by Kateryna Grynko

We'll look for a solution.


Invalid Date using new Date(_createdAt...

Posted: Wed Jun 05, 2013 8:22 pm
by Dupdroid

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

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