I’m trying to convert the string 11/24/2011 @ 01:15pm to a UNIX timestamp. The format is m-d-Y @ h:ia
I can’t seem to get strtotime to work with the string. Is there a way to reverse the data function? Is my only choice to create a new non-default php function to convert the string?
The server is running CentOS 5, Apache 2.2 and PHP 5.2.17.
Under PHP 5.2, you can use
strptimeto parse a date-time string with a specific format, then usemktimeto convert the result to a timestamp.This should be abstracted as a function, possibly two:
Support for parsing the period abbreviation appears to vary from OS to OS. If the above doesn’t work on a particular OS, try “%P” instead of “%p” or pass the time string through
strtoupper(or both). The following should work under any OS, though it’s preferable to getstrptimeto handle the entirety of the parsing, as the following is less suitable as the basis for a genericstrptimestampfunction.