Changing date format
Moderator: General Moderators
Changing date format
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?
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Changing date format
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
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Changing date format
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.AbraCadaver wrote: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