Answers. //Get value of input text var dt = $("input[type=text]"). val(). split('-'); var date = dt[2] +"-"+ dt[1] +"-"+ dt[0];
Fiddle link : http://jsfiddle.net/7LXPq/93/
Two problems in this:
Please follow the fiddle link for demo:
var now = new Date();
var day = ("0" + now.getDate()).slice(-2);
var month = ("0" + (now.getMonth() + 1)).slice(-2);
var today = now.getFullYear()+"-"+(month)+"-"+(day) ;
$('#datePicker').val(today);
document.getElementById("datePicker").valueAsDate = new Date()
should work.
Update: I'm doing this with date.toISOString().substr(0, 10)
. Gives the same result as the accepted answer and has good support.
var today = new Date().toISOString().split('T')[0];
$("#datePicker").val(today);
Above code will work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With