How to set default value to the input[type="date"]
The date should take the format YYYY-MM-DD
. Single digit days and months should be padded with a 0. January is 01.
From the documentation:
A string representing a date.
Value: A valid full-date as defined in [RFC 3339], with the additional qualification that the year component is four or more digits representing a number greater than 0.
Your code should be altered to:
<input type="date" value="2013-01-08">
Example jsfiddle
<input type="date" id="myDate" />
Then in js :
_today: function () {
var myDate = document.querySelector(myDate);
var today = new Date();
myDate.value = today.toISOString().substr(0, 10);
},
A possible solution:
document.getElementById("yourDatePicker").valueAsDate = new Date();
Using Moment.js:
var today = moment().format('YYYY-MM-DD');
document.getElementById("datePicker").value = today;