php and mysql -> december 31st, 1969

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
xionhack
Forum Contributor
Posts: 100
Joined: Mon Nov 10, 2008 9:22 pm

php and mysql -> december 31st, 1969

Post 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!
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

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

Post by Christopher »

What is in $date? It is probably an illegal value. Unix timestamps start on January 1st 1970 (which should be a clue).
(#10850)
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

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

Post 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.
maneetpuri
Forum Commoner
Posts: 60
Joined: Tue Oct 07, 2008 6:32 am

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

Post 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
xionhack
Forum Contributor
Posts: 100
Joined: Mon Nov 10, 2008 9:22 pm

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

Post 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.
xionhack
Forum Contributor
Posts: 100
Joined: Mon Nov 10, 2008 9:22 pm

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

Post by xionhack »

Sorry! It was my bad. I had the wrong variable. Its working now with strotime($date)
Post Reply