0

I've been working on a PHP powered site, and made use of this very nice jquery-based timepicker: http://sourceforge.net/projects/pttimeselect/

However I need to be able to convert the time that this outputs, which is styled as 1:00 PM, to hh:mm:ss that I can insert into a MySQL database.

How can this be done with PHP?

Chris
  • 282
  • 5
  • 19

1 Answers1

0

This can be achieve pretty simply with strtotime().

So let's say you're starting off with "1:30 PM", and want to get that to "13:00:00". The advantage to this, for me, is to pull from the database only results with a time that is later than right now, and this is quite possible with the hh:mm:ss format. This code will do it:

$twelveHourTime = "1:30 PM";

$twentyFourHourTime = (date("H:i", strtotime($twelveHourTime))) . ":00";

And that's it! You can check it out here: http://sandbox.onlinephpfunctions.com/code/a8957d18717c5ccb43c1701551ea8399156fd84f

Chris
  • 282
  • 5
  • 19