Is there a way to set a datepicker to a given date?
I have tried this:
<input type="date" name="dob" value="<?php echo date('yyyy-mm-dd', escape($user->data()->dob)); ?>"/>
but it doesn't work.
I just want to know if it is possible, but it can't just be set to 'now'. The only help I can see online is string manipulation, but not actually setting the datepicker.
You can set the date by using the datepicker function:
$("input[type=date]").datepicker(
"setDate", "<?php echo date('Y-m-d')"
);
You need to check the format also of date in datepicker.
Or You can do this:
<input type="date" name="dob"
value="<?php echo date('Y-m-d', strtotime(escape($user->data()->dob))); ?>"/>
You need to add the strtotime function also.
With jQquey Datepicker
$(function () {
$("#dateSelector").datepicker({
dateFormat: "dd/mm/yy",
changeMonth: true,
changeYear: true
});
});
$("#dateSelector").datepicker("setDate", "10/12/2012");
Check the FIDDLE
try this for today date:
<input type="date" value="<?php echo date('Y-m-d'); ?>" />
change your format string:
value="<?php echo date('YYYY-mm-dd', escape($user->data()->dob)); ?>"
also make sure escape($user->data()->dob));
is returning date string.
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