Pretty Dates from MySQL DateTime
June 13th, 2008
If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!
So I'm working on a project where I want to show a formatted join date on a user profile page. The join date, of course, is stored in a MySQL database using the datetime column type. I know you can use the MySQL built in function DATE_FORMAT, but I wanted to be able to do this right in my PHP rather than in a query.
So here's an easy, one-line bit of code to give you a date in any format you choose using your datetime value from your database result:
Is this helpful for you? Am I trying to roll a square wheel here and you know a better way? Comment and let me know!
Tags: php, mysql, datetime, pretty dates