0

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.

user2588317
  • 109
  • 2
  • 10

2 Answers2

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
  • 43,914
  • 5
  • 48
  • 61
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
  • 6,833
  • 9
  • 52
  • 90