我使用的是从日期到结束日期的日期选择器。
在PHP中发布这些日期时,日期格式为mm/dd/yyyy。
我需要将其转换为MySQL格式yyyy-mm-dd-
可以这样做吗?
$from = $_GET['from'];
$phpdate = strtotime( $from );
$from_date = date( 'Y-m-d', $phpdate );
我试过了,但没用。
您应该使用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");
在此处尝试此检查maual
$from = $_GET['from'];
$phpdate=$from;
$fromdate = date("Y-m-d", strtotime($phpdate));
试试这个就行了:
$from = $_GET['from'];
$phpdate=$from;
$fromdate = date("Y-m-d",strtotime($phpdate));
试试这个
$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);
date("Y-m-d", strtotime($_GET['<name>']));