55

I have a time as a string, for example:

$time = '5:36 pm';

I require this to be in 24 hour format (i.e. 17:36), however I don't know which functions I need to use to convert it. Please help.

Mike
  • 23,542
  • 14
  • 76
  • 87
sugesh
  • 621
  • 1
  • 5
  • 7
  • Post your code please. However: `date('H:i' [, $timestamp])`. Check http://www.php.net/manual/en/function.date.php – Fabio Mora Jan 05 '12 at 12:07
  • 4
    It's a real question, I just searched Google with almost exactly the same question myself, and it's reasonable not to have any code for something this simple as you might not know where to start. The proof that it's a real question is how many upvotes the answer has. – Matthew Lock Oct 24 '13 at 09:43
  • 3
    I edited this question to show a **bit** more code and I'm voting to reopen it because it's an old question, many others are duplicates of this one, it appears in the top positions for related searches, and it actually has an answer, so it *is* a real question in my opinion. – Mike Nov 20 '15 at 00:46

1 Answers1

197
// 24-hour time to 12-hour time 
$time_in_12_hour_format  = date("g:i a", strtotime("13:30"));

// 12-hour time to 24-hour time 
$time_in_24_hour_format  = date("H:i", strtotime("1:30 PM"));
Charles
  • 50,943
  • 13
  • 104
  • 142
Sudhir Bastakoti
  • 99,167
  • 15
  • 158
  • 162