APW APW - 25 days ago 10
Javascript Question

Converting Javascript String to Datetime

I have a text box that is populated from a datepicker in Javascript. The date is stored as

30-Jan-2013
. I want to convert this to a date so I can use it in other calculations.

I have tried

var date1 = new Date(document.getElementById('textbox').value)


but this returns
Nan


if I drop the
new Date
part e.g.

var date1 = (document.getElementById('textbox').value


I get the date
30-Jan-2013
I just don't seem to be able to convert this?

Answer

Looks like Date.parse is not going to work because the format the datepicker is returning.

You might want to look at the following thread for parsing solutions or change your format that the datepicker outputs to one of the supported formats.

How can I convert string to datetime with format specification in JavaScript?

http://blog.dygraphs.com/2012/03/javascript-and-dates-what-mess.html

Useful parse info:

http://msdn.microsoft.com/en-us/library/ie/ff743760(v=vs.94).aspx