imarockstar Posted August 28, 2008 Share Posted August 28, 2008 Whats the best way to store a date into a DB so that I can sort the results by date but also display the date on the site in a way people can understand ie. September 10th 2008 b Link to comment https://forums.phpfreaks.com/topic/121751-date-help/ Share on other sites More sharing options...
obsidian Posted August 28, 2008 Share Posted August 28, 2008 Use the MySql type DATE unless you also need the time, then use DATETIME. You can sort on the column, and you can use DATE_FORMAT() to retrieve the data in the format you desire, or it is extremely easy to parse with PHP as well. Link to comment https://forums.phpfreaks.com/topic/121751-date-help/#findComment-628090 Share on other sites More sharing options...
pocobueno1388 Posted August 28, 2008 Share Posted August 28, 2008 Store it in this format: yyyy-mm-dd Then when you retrieve it from the database, you can easily manipulate how you want it displayed with either a MySQL function, or the PHP date() function. Link to comment https://forums.phpfreaks.com/topic/121751-date-help/#findComment-628093 Share on other sites More sharing options...
obsidian Posted August 28, 2008 Share Posted August 28, 2008 Store it in this format: yyyy-mm-dd Just some clarification... YYYY-MM-DD is the MySql date format. So, if you are using this (which is by far the best scenario for multiple reasons), be sure to declare your data type as DATE, too. Link to comment https://forums.phpfreaks.com/topic/121751-date-help/#findComment-628113 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.