Forum Moderators: coopster

Message Too Old, No Replies

DATETIME messed up in PHP's date() function

         

Gero_Master

6:37 pm on Apr 7, 2006 (gmt 0)

10+ Year Member



hi!

I'm using DATETIME in my MySQL database. When I try to retrieve it and change it to correct format with PHP's date function, it shows all values false.

date("D, j M Y H:i:s", $article['pubdate'])

outputs: 1. tammikuuta 1970, 2:33:26

tammikuuta = January

dreamcatcher

8:18 pm on Apr 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try the DATE_FORMAT function:

[dev.mysql.com...]

dc

coopster

9:30 pm on Apr 7, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I agree, I would format the date using the database functions available if possible too. Let the DB do the work. The reason your date() [php.net] function is not working is because it expects the second parameter to be an integer timestamp, not an ISO date.

whoisgregg

10:09 pm on Apr 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can also have PHP convert it to a timestamp. Take a look at strtotime() [php.net] to get started.

date("D, j M Y H:i:s", strtotime($article['pubdate']) );

Gero_Master

7:06 am on Apr 8, 2006 (gmt 0)

10+ Year Member



Thank you very much! It works now perfectly!