Testadmin Testadmin - 1 year ago 91
PHP Question

How to get AM/PM from a datetime in PHP

I have a date time in a variable. My format is

08/04/2010 22:15:00
. I want to display this like
10.15 PM
. How to do this in PHP?

Thanks in advance

Answer Source

You need to convert it to a UNIX timestamp (using strtotime) and then back into the format you require using the date function.

For example:

$currentDateTime = '08/04/2010 22:15:00';
$newDateTime = date('h:i A', strtotime($currentDateTime));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download