Reputation: 828
I'm trying to convert datetimte to something shorter, but i get some error as below.
Warning:
date_format()
expects parameter 1 to be DateTime, string given in ...
CODE
$datetime = '2012-03-24 17:45:12';
$time = date_format($datetime, 'g:i A');
echo $time;
What i'm i doing wring? Thanks.
Upvotes: 0
Views: 183
Reputation: 646
date_format
formats a date object. You have a strong.
Try date("g:I A", strtotime($datetime))
Upvotes: 0
Reputation: 4526
this will also work for you-
$datetime = date_create('2012-03-24 17:45:12');
$time = date_format($datetime, 'g:i A');
echo $time;
Upvotes: 0
Reputation: 44874
Try this with DateTime
$date = new DateTime("2012-03-24 17:45:12");
echo $date->format("g:i A");
Upvotes: 2