Reputation: 7240
I have the following date:
2014-09-26 11:30:00
I need to display it in the page like:
26-September-2014 At 11:00
I have the following code to do this:
$exp_datetime = date('d-F-Y At H:s', strtotime($exp_datetime)); // So stupid I know ;)
echo "Visit Date: " . $exp_datetime;
and I get the following result:
Visit Date: 26-September-2014 AM30 11:00
I need to know how can i get the required result!
Many many thanks in advance! :)
Upvotes: 0
Views: 97
Reputation: 13728
Also using datetime
$d = new DateTime('2014-09-26 11:30:00');
echo $d->format('d-F-Y \A\t H:s');
Upvotes: 1
Reputation: 41885
Alternatively, you could also use strftime() in this case:
echo strftime('%d-%B-%G At %H:%M', strtotime('2014-09-26 11:30:00'));
// 26-September-2014 At 11:30
Upvotes: 1
Reputation: 61
You need to escape your "At" word. Because, as described here: http://php.net/manual/fr/datetime.format.php "A" and "t" are reserved characters.
So your correct code should be:
$exp_datetime = date('d-F-Y \A\t H:s', strtotime($exp_datetime));
Upvotes: 2
Reputation: 8369
$exp_datetime = date('d-F-Y At H:s', strtotime($exp_datetime));
^
At
is not an accepted date format character. You can do like
echo "Visit Date: ". date('d-F-Y', strtotime($exp_datetime));
echo " At ". date('H:s', strtotime($exp_datetime));
Upvotes: 1