note 43999 added to function.strtotime

From: Date: Mon, 12 Jul 2004 07:15:32 +0000
Subject: note 43999 added to function.strtotime
Groups: php.notes 
Request: Send a blank email to php-notes+get-73080@lists.php.net to get a copy of this message
While converting a database from MS SQL Server to MySQL running on Linux, I had problems converting Microsoft's smalldatetime field with dates where the month was < 10. Here's the function I used to solve the problem with strtotime getting the month/day mixed up. I'm sure there's a simpler way to convert the month from Jan to 01, but this gets the job done: <?php function datetotime($date) { // MS SQL Server will return with this format: Sep 03 2003 06:01PM list($month, $day, $year, $hour, $minute, $ampm) = sscanf($date,'%s %d %d %d:%d%s'); $monthconv = array( 'Jan' => '01', 'Feb' => '02', 'Mar' => '03', 'Apr' => '04', 'May' => '05', 'Jun' => '06', 'Jul' => '07', 'Aug' => '08', 'Sep' => '09', 'Oct' => '10', 'Nov' => '11', 'Dec' => '12' ); $monthnum = $monthconv[$month]; $datestring = "$year-$monthnum-$day $hour:$minute:00 $ampm"; $time = strtotime($datestring); if ($time == -1) { die("Problem with $date --> $datestring\n"); } return $time; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.strtotime.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+43999 Delete -- http://master.php.net/manage/user-notes.php?action=delete+43999&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+43999&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#73080) next »