Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set date picker to a given date [duplicate]

Tags:

html

date

php

mysql

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.

like image 681
VaMoose Avatar asked Dec 25 '13 05:12

VaMoose


3 Answers

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.

like image 113
Code Lღver Avatar answered Nov 05 '22 23:11

Code Lღver


With jQquey Datepicker

$(function () {
    $("#dateSelector").datepicker({
        dateFormat: "dd/mm/yy",
        changeMonth: true,
        changeYear: true
    });
});
$("#dateSelector").datepicker("setDate", "10/12/2012");

Check the FIDDLE

like image 28
Napster Avatar answered Nov 05 '22 22:11

Napster


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.

like image 1
Zaheer Ahmed Avatar answered Nov 05 '22 21:11

Zaheer Ahmed