RE: [PHP] Weird Date problem driving me crazy...
| From: | Boaz Yahav | Date: | Sun, 13 Jul 2003 18:59:24 +0000 |
| Subject: | RE: [PHP] Weird Date problem driving me crazy... | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-155013@lists.php.net to get a copy of this message | ||
Thanks John, your answer is right on the $$$.
Changing the query to something like : SELECT
UNIX_TIMESTAMP(ProblemStart) as ProblemStart
solved the problem.
Do i feel sheepish... actually double sheepish cause i already solved
this
long ago and forgot about it :(
Sincerely
berber
Visit http://www.weberdev.com/ Today!!!
To see where PHP might take you tomorrow.
-----Original Message-----
From: John W. Holmes [mailto:holmes072000@charter.net]
Sent: Sunday, July 13, 2003 5:01 PM
To: Boaz Yahav
Cc: php-general@lists.php.net
Subject: Re: [PHP] Weird Date problem driving me crazy...
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