-1

I have a large list of dates and times, a sample look like this...

11/22/2018 01:16:14 AM
11/23/2018 10:59:39 PM

I assume the dates are in the 'm/d/Y h:i:s A' format, I am looking for the quickest and easiest way in PHP to convert these to an epoch timestamp.

Anyone have an example?

fightstarr20
  • 11,682
  • 40
  • 154
  • 278
  • 1
    Have a look at [`strtotime()`](http://php.net/manual/en/function.strtotime.php) – Tigger Jan 25 '19 at 10:00
  • 1
    What's your approach so far? – Daniel W. Jan 25 '19 at 10:03
  • Possible duplicate of [How to convert MySQL time to UNIX timestamp using PHP?](https://stackoverflow.com/questions/4577794/how-to-convert-mysql-time-to-unix-timestamp-using-php) – Tigger Jan 25 '19 at 12:04

2 Answers2

4

Use strtotime function

echo strtotime("11/22/2018 01:16:14 AM");
Tejashwi Kalp Taru
  • 2,994
  • 2
  • 20
  • 35
1

You can do it this object oriented way:

$format = 'm/d/Y h:i:s A';
$date = DateTime::createFromFormat($format, '11/22/2018 01:16:14 AM');
echo $date->getTimestamp();
MatejG
  • 1,393
  • 1
  • 17
  • 26