If i have a string with format "MM-YYYY" like 04-2016
,
how to get them into datetime format mysql which is "YYYY-MM-dd hh:mm:ss".
I wonder like this : 2016-04-01 00:00:00, I am using php with mysql.
If i have a string with format "MM-YYYY" like 04-2016
,
how to get them into datetime format mysql which is "YYYY-MM-dd hh:mm:ss".
I wonder like this : 2016-04-01 00:00:00, I am using php with mysql.
$d = '04-2016';
$date = DateTime::createFromFormat('d-m-Y', ('01-'.$d));
$date->setTime(0, 0, 0);
echo $date->format('Y-m-d H:i:s'); // Outputs 2016-04-01 00:00:00
Something like the above will allow you to get the format you want in PHP, then you just have to insert it into your database as you currently are.
you have date time formate with Am and pm then use below code
$d='03-03-2016 03:07:22';
echo date('Y-m-d h:i:s a',strtotime($d));