storing date in datetime column
| From: | afan at afan dot net | Date: | Tue, 09 Jan 2007 17:10:32 +0000 |
| Subject: | storing date in datetime column | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-246794@lists.php.net to get a copy of this message | ||
hi,
$date = "January 8 2007 11:23 pm";
and have to store it on db in datetime column as yyyy-mm-dd HH:ii:ss.
Is there any function that will "translate" $date in format I need to
store it in DB?
Right now I was thinking to do like this:
$date_new = explode(' ', $date);
switch($date_new[0])
{
case 'January':
$month = '01';
break;
case 'February':
$month = '02';
break;
// etc.
}
$date_time = explode(':', $date_new[3]);
$hours = ($date_new[4] == 'pm') ? ($date_time[0] + 12) : $date_time[0] ;
$time_new = $hours.':'.$date_time[1].':00';
$date_final = $date_new[2].'-'.$month.'-'.$date_time[1].' '.$time_now;
Is there better solution than this above?
Thanks.
-afan