在jquery日期选择器中解析php日期和时间


Parsing php date and time in jquery datepicker

我在数据库中存储了一个日期时间作为

2014-10-29 19:44:22

我正在尝试设置DatePicker 的最小日期

以下是php中的代码。

$creationDate =  $record['creationDate'];
                    $timestamp = strtotime($creationDate);
                    $year  =  date("y", $timestamp);
                    $month =  date("m", $timestamp);
                    $day   =  date("d", $timestamp);

稍后在jquery 中

 $( "#calendar" ).datepicker({ minDate: new Date(<?php echo $year . "," .$month . "," .$day  . ",1"?>)});

结果不起作用有什么办法吗?

试试看。

$( "#calendar" ).datepicker({
     minDate: new Date(<?php
         echo date('Y, m, d',strtotime($yourDateVar));
     ?>)
});

尝试

     $("#calendar").datepicker({
            dateFormat: 'yy-mm-dd',
            minDate: '<?php echo date("Y-m-d",strtotime($creationDate)); ?>',
        });

根据需要更改dateFormat: 'yy-mm-dd',date('Y-m-d')格式。

例如,如果日期选择器显示:-2020/03/26,则

dateFormat: 'yy/mm/dd',
minDate: '<?php echo date("Y/m/d",strtotime($creationDate)); ?>',