-3

If I have hours in the following format : 2:30 am how can I turn it into : 14:30:00

and if I got the date 2013-07-17 and the time 14:30:00 how can I turn it to a datatimestamp ? for example this will produce : 1374053400

thanks.

gilm501
  • 151
  • 1
  • 2
  • 8
  • 1
    This question has already been answered: http://stackoverflow.com/questions/10905959/php-turn-pm-and-am-into-24-hour – user2699706 Sep 21 '13 at 23:09

2 Answers2

2

am is before noon, not after..

This is what I would do:

$timeString = '2:30 am';
$dateString = '2013-07-17';
$timeZone = new DateTimeZone('Europe/London');
$date = new DateTime($dateString . ' ' . $timeString, $timeZone);

echo $date->format('H:i:s'); // 02:30:00
echo $date->getTimestamp(); // the timestamp as int
cueloop
  • 141
  • 1
  • 5
-1

Have you tried to search in this site? :)

The second question has a really-similar one here: How to convert date to timestamp in PHP?

As for the first one, the answer is in the official php documentation: http://php.net/manual/es/function.date.php

Community
  • 1
  • 1
versvs
  • 643
  • 2
  • 12
  • 30