Page 1 of 1
Changing date format
Posted: Fri May 07, 2010 3:11 pm
by marcdd2
I have a variable that is set as a date in mySQL DB that is pulled from the DB, posted to the next page, and then displayed. if i just display the variable it comes out as 2010-06-20. If I try to change the format with date("m/d/y", $eventdate) it is displayed as 12/31/69. I assume the php engine doesn't think that 2010-06-20 is a valid date. Can someone help?
Re: Changing date format
Posted: Fri May 07, 2010 3:30 pm
by AbraCadaver
Well, it is not a valid unix timestamp which is what date() expects. Try:
http://dev.mysql.com/doc/refman/5.1/en/ ... ate-format
Re: Changing date format
Posted: Fri May 07, 2010 3:37 pm
by John Cartwright
Although I recommend what AbraCadaver has suggested, I just want to add why your solution probably isn't working. Basically, mysql timestamps are not the same as a unix timestamp (YYYYMMDD DDMMSS vs seconds since epoch Dec 31 1969). Therefore, you need to convert your mysql timestamp to a unix timestamp if you want to format the string using php's date function, which simply involves passing mysql timestamp through strtotime() and passing that to the date() function instead.