PDA

View Full Version : PHP/MySQL datetime weirdness



nobody
August 21st, 2006, 12:50 AM
So I have a MySQL datetime record which is 2006-08-20 21:13:25

So I extract that data with PHP date function... something to the extent of date("r", $blah)

However it spits out this gem: Wed, 31 Dec 1969 16:33:26 -0800

Is there something I'm doing horribly wrong? I'm confused.

GrzKax
August 21st, 2006, 02:55 AM
Well first of all the function date() reguires two things. First a format of how you want the date outputted, and next an INTEGER timestamp. For more info check: php.net (http://dk2.php.net/date)

nobody
August 21st, 2006, 03:13 AM
Yeah I've read all the documentation on both MySQL and PHP. As you'll see my date function I posted does have both arguments, "r" format, $blah timestamp.

GrzKax
August 21st, 2006, 03:52 AM
Yes, but the format of $blah is wrong. It has to be something like '75647385746' (Number of seconds since January 1st 1970 i think).

nobody
August 21st, 2006, 04:25 AM
Oh it has to be unix time stap garbage? That's weird cause I've seen examples like mine where it's worked. I'm not sure if that's entirely right. I know you have to use that format to get mktime() spit out something useful.

Hmmm.

GrzKax
August 21st, 2006, 04:31 AM
Well when reading through the php site it clearly says:


The optional timestamp parameter is an integer Unix timestamp

But i'm sure there are ways to make the format you're saving come out right when echoed from php.

nobody
August 21st, 2006, 06:44 AM
Ah, guess I kinda skipped over that part. I suppose there's no reason not use the timestamp, might as well go that route. Thanks for the info :)

skOOb
August 21st, 2006, 08:19 AM
try
date("r", strtotime($blah))

nobody
August 21st, 2006, 04:18 PM
Good call Skoob! I knew there was an easy solution out there. Thanks :love: