note 37031 added to function.date
| From: | fireball at sizzling dot com | Date: | Fri, 31 Oct 2003 09:21:47 +0000 |
| Subject: | note 37031 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-59562@lists.php.net to get a copy of this message | ||
Under 4.3.3 I found that mktime() doesn't work very well when working with a normal datetime
fields in mysql. The normal format of these are "2003-10-30 10:09:00".
Using strtotime() works much better:
$time = "2003-10-30 10:09:00";
echo date("F dS, Y h:ia",strtotime($time));
will output a correct date:
October 30th, 2003 10:09am
where as:
$time = "2003-10-30 10:09:00";
list($date1,$time1) = explode(" ",$time);
list($year,$month,$day) = explode("-",$date1);
list($hour,$min,$sec) = explode(":",$time1);
$arr = array($hour,$min,$sec,$month,$day,$year);
$time = implode(",",$arr);
echo date("F dS, Y h:ia", mktime($time));
will produce an incorrect, changing date e.g.:
October 31st, 2003 10:14am
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+37031
Delete -- http://master.php.net/manage/user-notes.php?action=delete+37031&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+37031&report=yes
Search -- http://master.php.net/manage/user-notes.php