input type="datetime-local" valueAsDate return null

Viewed 603

<input name="datetime" type="datetime-local" />

The above input only works with valueAsNumber, when I switch to valueAsDate it returns null.

I guess it's because failed to convert into Date?

1 Answers

Your input is not a date, it is a datetime

You are correct, it failed to convert into Date.

You could do this instead:

var datevalue = new Date(myinput.value);
Related