convert datepicker date to mysql date
18,681
Solution 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");
Solution 2
Try this Check maual here
$from = $_GET['from'];
$phpdate=$from;
$fromdate = date("Y-m-d", strtotime($phpdate));
Solution 3
Try this it will work :
$from = $_GET['from'];
$phpdate=$from;
$fromdate = date("Y-m-d",strtotime($phpdate));
Author by
user3312792
Updated on June 12, 2022Comments
-
user3312792 almost 2 years
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.