Here is what I have:
$dateFormat = \'M d, Y\';
$dateString = \'January 23, 2010\';
What I need is a timestamp of $dateString s
Use strptime, mktime and strftime:
$ftime = strptime($dateString, $dateFormat);
$timestamp = mktime($ftime['tm_hour'], $ftime['tm_min'], $ftime['tm_sec'], 1,
$ftime['tm_yday'] + 1, $ftime['tm_year'] + 1900);
echo strftime('Y-m-d', $timestamp);
Please note that strptime is not implemented on Windows platforms.
Note that the arguments to mktime are somewhat unusual - strptime returns a day of the year (between 0-365, inclusive) rather than a day of the month and a month, so we set the month parameter to mktime to 1, and add 1 to the day of the year. Also, strptime returns years since 1900 for the year value it returns, so we need to add 1900 to the year before passing it through to mktime.
Also, you might want to check whether $ftime is FALSE before passing it into mktime. strptime returning FALSE denotes that the inputs $dateString is not a valid date format according to $dateFormat.