i will set today date in datepicker input type date in chrome.
$(
Your code would have worked if it had been in this format: YYYY-MM-DD
, this is the computer standard for date formats http://en.wikipedia.org/wiki/ISO_8601
Jquery version
var currentdate = new Date();
$('#DatePickerInputID').val($.datepicker.formatDate('dd-M-y', currentdate));
I usually create these two helper functions when using date inputs:
// date is expected to be a date object (e.g., new Date())
const dateToInput = date =>
`${date.getFullYear()
}-${('0' + (date.getMonth() + 1)).slice(-2)
}-${('0' + date.getDate()).slice(-2)
}`;
// str is expected in yyyy-mm-dd format (e.g., "2017-03-14")
const inputToDate = str => new Date(str.split('-'));
You can then set the date input value as:
$('#datePicker').val(dateToInput(new Date()));
And retrieve the selected value like so
const dateVal = inputToDate($('#datePicker').val())
var today = new Date().toISOString().split('T')[0];
$("#datePicker").val(today);
Above code will work.
You can only use date in input type="date"
as in format YYYY-MM-DD
I have implemented helper as formatDate
in NODE.js express-handlebars, don't need to be worry ... just use format as described in first line.
e.g:
< input type="date" id="date" name="date" class="form-control" value="{{formatDate invoice.date 'YYYY-MM-DD'}}" />