I want to convert date format in php.
I have a variable $date = '05-27-2016 15:30'
. I want to convert it into '3:30 PM 27-May-2016'
.
I try this one date('H:i A d-M-Y',strtotime($date))
but it gives wrong result.
How do I do that?
I want to convert date format in php.
I have a variable $date = '05-27-2016 15:30'
. I want to convert it into '3:30 PM 27-May-2016'
.
I try this one date('H:i A d-M-Y',strtotime($date))
but it gives wrong result.
How do I do that?
Use createFromFormat function
$date = DateTime::createFromFormat('m-d-Y H:i', '05-27-2016 15:30');
echo $date->format('h:i A d-M-Y'); // 3:30 PM 27-May-2016
As i Commented out both the format, You need to change the format before changing final for final format.
If you need
3
at03
, just useg
ath
.
General: Online Check
$date = '27-05-2016 15:30';
echo date('h:i A d-M-Y', strtotime($date)); //03:30 PM 27-May-2016
Or ,
using Object Oriented: Online Check
$date = '05-27-2016 15:30';
$date = DateTime::createFromFormat('m-d-Y H:i', $date);
echo $date->format('h:i A d-M-Y');