Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert datepicker date to mysql date [duplicate]

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.

like image 951
user3312792 Avatar asked Feb 25 '15 07:02

user3312792


3 Answers

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");
like image 157
Abhik Chakraborty Avatar answered Nov 13 '22 17:11

Abhik Chakraborty


Try this Check maual here

$from = $_GET['from'];
$phpdate=$from;
$fromdate = date("Y-m-d", strtotime($phpdate)); 
like image 35
I'm Geeker Avatar answered Nov 13 '22 15:11

I'm Geeker


Try this it will work :

$from = $_GET['from'];
$phpdate=$from;
$fromdate = date("Y-m-d",strtotime($phpdate));
like image 1
Creative Learner Avatar answered Nov 13 '22 16:11

Creative Learner