Re: Weird Date problem driving me crazy...

From: Date: Sun, 13 Jul 2003 15:01:17 +0000
Subject: Re: Weird Date problem driving me crazy...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-155004@lists.php.net to get a copy of this message
Boaz Yahav wrote:
I have two date strings coming out from MySQL. Both fields are defined as datetime. When i come to print them like this : Echo"<B>Ticket Opened</B> : " . date("l, F jS Y H:i",$row->OpenDate) . "<BR>"; Echo"<B>Problem Start</B> : " . date("l, F jS Y H:i",$row->ProblemStart) . "<BR>"; I get : Ticket Opened : Sunday, July 13th 2003 13:37 Problem Start : Thursday, January 1st 1970 02:33 Notice that the 2nd date is wrong and it's some kind of default that the function returns. Only if i add strtotime() and only to the 2nd field do i get the correct answer : Ticket Opened : Sunday, July 13th 2003 13:37 Problem Start : Saturday, July 12th 2003 20:36
date() expects a UNIX timestamp to be passed to it. MySQL does not store dates as a UNIX timestamp in DATE, DATETIME, or TIMESTAMP columns. strtotime() will take a MySQL timestamp, though, and convert it to a UNIX timestamp. Also look into using DATE_FORMAT() in your query to format the data there so you don't have to do anything in PHP. -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ PHP|Architect: A magazine for PHP Professionals – www.phparch.com

« previous php.general (#155004) next »