How to convert future date to matching timestamp

alakentu

New Member
I have a function that takes a string date in the format 08/24/2010 and turns it into a timestamp. The problem I have is that dates such as 08/24/2090 are converted improperly.Here is my function:\[code\]/*** Converts a date to a timestamp* for a date formatted such as: 08/24/2010 12:00:00, 08-24-2010 12:00:00 or 08/24/2010* * @param string date* @return string*/public static function dateToTimeStamp($date){ if (!strstr($date, ' ')) $date .= ' ' . date('h:i:s'); list($date, $time) = explode(' ', $date); list($month, $day, $year) = (strstr($date, '/') ? explode('/', $date) : explode('-', $date)); list($hour, $minute, $second) = explode(':', $time); $timestamp = mktime($hour, $minute, $second, $month, $day, $year); return date('Y-m-d h:i:s', $timestamp);} \[/code\]I just passed in 09/30/2090 and I get back 1969-12-31 04:00:00 but when I pass in 09/30/2020, I get back 2020-09-30 08:54:44.
 
Back
Top