4

I'm getting a time value from a database call in the following format:

HH:MM:SS

Here are some examples:

08:15:00
22:45:00

I need to however convert these and display them, using the above examples, as follows:

8:15 AM
10:45 PM

and so on. I've been playing around with the strtotime options but everything I've tried has failed so far, and I'm not sure if that's the correct function to even use. I need go from to:

$bookingTime = "08:15:00"

to:

$bookingTime = "8:15 AM"
Nitsan Baleli
  • 5,393
  • 3
  • 30
  • 52
user982124
  • 4,416
  • 16
  • 65
  • 140

4 Answers4

7

you have to try this one:

echo date("g:i A", strtotime($bookingTime));
3

You can try something like this as well

$d = new DateTime('08:15:00'); 
echo $d->format( 'g:i A' );
Ram Sharma
  • 8,676
  • 7
  • 43
  • 56
1

try this:

$currentDateTime = '08:15:00';
$newDateTime = date('h:i A', strtotime($currentDateTime));

echo $newDateTime;

result: 08:15 AM

possible duplicate of this question

Community
  • 1
  • 1
Nitsan Baleli
  • 5,393
  • 3
  • 30
  • 52
-1

it's working try it

 $bookingTime = "22:45:00";

  list($hour, $minute, $second) = explode(':', $bookingTime);
  $date_time1 = mktime($hour, $minute, $second);
  echo date('g:i A',$date_time1);
Nikhil Vaghela
  • 222
  • 1
  • 14