convert datepicker date to mysql date [duplicate]

社会主义新天地 提交于 2020-01-03 10:44:33

问题


I am using datepicker with from and to dates.

When posting these dates in PHP the date format is mm/dd/yyyy.

I need to convert this to MySQL format yyyy-mm-dd

Can it be done like this?

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

I tried this but it doesn't work.


回答1:


You should use DateTime::createFromFormat

Ex:

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

So in your case

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



回答2:


Try this Check maual here

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



回答3:


Try this it will work :

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



回答4:


Try This

$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);



回答5:


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


来源:https://stackoverflow.com/questions/28713420/convert-datepicker-date-to-mysql-date

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!