将datepicker日期转换为mysql日期

时间:2015-02-25 07:25:33

标签: php jquery mysql date datepicker

我正在使用带有和来自日期的datepicker。

在PHP中发布这些日期时,日期格式为mm / dd / yyyy。

我需要将其转换为MySQL格式yyyy-mm-dd

可以这样做吗?

$from = $_GET['from'];
$phpdate = strtotime( $from );
$from_date = date( 'Y-m-d', $phpdate );

我尝试了这个,但它不起作用。

5 个答案:

答案 0 :(得分:9)

您应该使用 DateTime::createFromFormat

例如:

$date = DateTime::createFromFormat('m/d/Y','02/10/2015');
echo $date->format("Y-m-d");
// 2015-02-10

所以在你的情况下

$from = $_GET['from'];
$date = DateTime::createFromFormat('m/d/Y',$from);
$from_date = $date->format("Y-m-d");

答案 1 :(得分:2)

试试这个Check maual here

$from = $_GET['from'];
$phpdate=$from;
$fromdate = date("Y-m-d", strtotime($phpdate)); 

答案 2 :(得分:1)

试试这个会起作用:

$from = $_GET['from'];
$phpdate=$from;
$fromdate = date("Y-m-d",strtotime($phpdate));

答案 3 :(得分:0)

试试这个

$from = $_GET['from'];
$date_array=explode("/",$from);
$new_date_array=array($date_array[2], $date_array[0], $date_array[1]);
echo $new_date=implode("/",$new_date_array);

答案 4 :(得分:0)

date("Y-m-d", strtotime($_GET['<name>']));
相关问题