-3

I want to convert format d/m/Y - h:i:s A to a timestamp in PHP.

I tried:

$time = '26/07/2014 - 03:59:23 PM';
$time2 = strtotime($time);

But that returns null

Josh Davenport-Smith
  • 5,456
  • 2
  • 29
  • 40
  • `strtotime` doesn't know all formats. You can look up supported date formats here: http://php.net/manual/de/datetime.formats.php – CodeBrauer Jun 24 '15 at 13:41

1 Answers1

1

This is easiest when using the DateTime class:

$dateString = '26/07/2014 - 03:59:23 PM';
$datetime   = DateTime::createFromFormat('d/m/Y - h:i:s A', $dateString);

echo $datetime->getTimestamp();

An example of this code is here.

Phylogenesis
  • 7,775
  • 19
  • 27