I have a database that lists time as "100", "200", "1000", "1400", etc. What is the easiest way to turn this into something like "2:00 pm"? I really don't want to use a bunch of conditional operations if I don't have to.
Asked
Active
Viewed 143 times
2 Answers
3
To change the value to time using AM/PM you can do as
$time = '1400';
echo date('h:i A',strtotime($time));

Abhik Chakraborty
- 44,654
- 6
- 52
- 63
0
You can use the php date()
function. You can convert it to any format you want. Here is the documentation
For you case, you can do do:
<?php
$time = 1400;
echo date('h:i A', strtotime($time));
?>
This will print out 2:00 PM
Check it out live here

Krimson
- 7,386
- 11
- 60
- 97