0

I am working on a PHP file were I am pulling in timestamps from a database that come out as

Tue Sep 22 16:11:12 EDT 2015
Mon Nov 16 07:42:31 EST 2015

I was wondering how to convert dates of this format into unix time format.

jarlh
  • 42,561
  • 8
  • 45
  • 63
William Roberts
  • 319
  • 2
  • 5
  • 21
  • http://stackoverflow.com/questions/2167916/convert-one-date-format-into-another-in-php – Nikola Miljković Nov 16 '15 at 14:52
  • 4
    Possible duplicate of [How can I parse a date from a text file?](http://stackoverflow.com/questions/33650654/how-can-i-parse-a-date-from-a-text-file) – Andrius Nov 16 '15 at 14:53

2 Answers2

0

You can use the DateTime object

$dateTime = new DateTime('Tue Sep 22 16:11:12 EDT 2015');

echo $dateTime->getTimestamp();

The result would be 1442952672

Mihai Matei
  • 24,166
  • 5
  • 32
  • 50
0

If you look at the PHP manual for \DateTime::createFromFormat() or date(), you will find tables of codes accepted by \DateTime::createFromFormat(). Looking at them you will see that you need the following:-

$date = \DateTime::createFromFormat('D M d H:i:s T Y', 'Tue Sep 22 16:11:12 EDT 2015');
echo $date->getTimestamp();

Demo.

The 'd' in the format string may need to be a 'j' if day numbers < 10 are single digit.

vascowhite
  • 18,120
  • 9
  • 61
  • 77