1

How to get timestamp by Date & Date Format?

$date = "2014-08-21"; $format = "Y-m-d";

$timestamp = get_timestamp ($date,$format);

Ali Dbg
  • 63
  • 1
  • 2
  • 5
  • http://php.net/manual/en/function.date-create-from-format.php – AbraCadaver Aug 21 '14 at 19:52
  • possible duplicate of [Convert one date format into another in PHP](http://stackoverflow.com/questions/2167916/convert-one-date-format-into-another-in-php) – Machavity Aug 21 '14 at 20:04

1 Answers1

1

As simple as this:

$date = "2014-08-21"; $format = "Y-m-d";
$timestamp = \DateTime::createFromFormat($format, $date)->format('U');

Addition based on the comment below...

For PHP older thatn 5.3 the following code can be used:

$timestamp = strtotime($date);

In this case you should make sure that your date format is one of the supported formats. In your example it is "Year, month and day with dashes" so it should work.

Stepashka
  • 2,648
  • 20
  • 23