I am trying to come up with a way to use PHP to convert any date that is in a format below, to a unix timestamp. I was wondering if someone can help me accomplish this.
This is what I tried, which didn’t work:
$expiration_date = '11/22/12';
$timestamp = strtotime(date("m/d/y", $expiration_date));
You don’t need the
date()part.Just do this:
http://php.net/manual/en/function.strtotime.php
The problem with your example is you’re passing a string to the
date()function.The
date()function requires a format string e.g.'m/d/y'and then the time as an int value.You’re passing it a string so it doesn’t work.
date(): http://php.net/manual/en/function.date.php