Page 1 of 1

php and mysql -> december 31st, 1969

Posted: Tue Dec 22, 2009 11:24 pm
by xionhack
Hello. Im pulling a date from mysql, but when i give it the

Code: Select all

]date('F j Y', $date)
format it outputs december 31st, 1969. If i dont try to give it the format, it outputs the correct date. Can somebody tell me what am i doing wrong? thanks!

Re: php and mysql -> december 31st, 1969

Posted: Wed Dec 23, 2009 1:02 am
by Christopher
What is in $date? It is probably an illegal value. Unix timestamps start on January 1st 1970 (which should be a clue).

Re: php and mysql -> december 31st, 1969

Posted: Wed Dec 23, 2009 1:32 am
by requinix
xionhack wrote:If i dont try to give it the format, it outputs the correct date.
You mean

Code: Select all

echo $date;
date() expects a number for the second argument. You didn't give it a number. date's way of complaining is to give January 1st 1970, but since you're west of GMT/UTC the timezone adjustment pushed it to the day before that.

You can convert the string to a number (most of the time) with strtotime.

Re: php and mysql -> december 31st, 1969

Posted: Wed Dec 23, 2009 5:04 am
by maneetpuri
Hi,

There is no problem with the syntax or the function the only issue is with the values you are using to get the parts of the date. The URL below will give you the exact list of parameters for date formats: -

http://in2.php.net/manual/en/function.date.php

Cheers,


~Maneet

Re: php and mysql -> december 31st, 1969

Posted: Wed Dec 23, 2009 9:05 pm
by xionhack
I tried converting them. When i output it without the date() it shows the correct date. Its in a date data field in the mysql table.

Re: php and mysql -> december 31st, 1969

Posted: Wed Dec 23, 2009 9:09 pm
by xionhack
Sorry! It was my bad. I had the wrong variable. Its working now with strotime($date)