limitphp Posted December 18, 2008 Share Posted December 18, 2008 How would you order by date in a query if the date is in this format (ex: 1999-10-31)? newest dates first..... assuming the date field is called copyrightDate? ORDER BY ??? thanks Link to comment https://forums.phpfreaks.com/topic/137586-order-by-date/ Share on other sites More sharing options...
premiso Posted December 18, 2008 Share Posted December 18, 2008 ORDER BY copyrightDate I think that should do the trick on it's own. If not try adding DESC or ASC after copyrightDate and see if that gets you what you are after. btw, that is a really bad format to store the time in. Timestamp is way more flexible and preferred =) Link to comment https://forums.phpfreaks.com/topic/137586-order-by-date/#findComment-719132 Share on other sites More sharing options...
Maq Posted December 18, 2008 Share Posted December 18, 2008 newest dates first..... You mean most recent... ORDER BY cpyrightDate DESC; Link to comment https://forums.phpfreaks.com/topic/137586-order-by-date/#findComment-719135 Share on other sites More sharing options...
limitphp Posted December 18, 2008 Author Share Posted December 18, 2008 ORDER BY copyrightDate I think that should do the trick on it's own. If not try adding DESC or ASC after copyrightDate and see if that gets you what you are after. btw, that is a really bad format to store the time in. Timestamp is way more flexible and preferred =) ok thanks. I'll change it to timestamp. When I change, will it still be the same, ORDER BY copyrightDate? Link to comment https://forums.phpfreaks.com/topic/137586-order-by-date/#findComment-719145 Share on other sites More sharing options...
premiso Posted December 18, 2008 Share Posted December 18, 2008 ORDER BY copyrightDate I think that should do the trick on it's own. If not try adding DESC or ASC after copyrightDate and see if that gets you what you are after. btw, that is a really bad format to store the time in. Timestamp is way more flexible and preferred =) ok thanks. I'll change it to timestamp. When I change, will it still be the same, ORDER BY copyrightDate? Probably need the DESC after it like Maq mentioned. Link to comment https://forums.phpfreaks.com/topic/137586-order-by-date/#findComment-719149 Share on other sites More sharing options...
Maq Posted December 18, 2008 Share Posted December 18, 2008 Yeah I think ASC is default if you don't specify. And since you want most recent, you want descending because that will list greatest to least, so to speak. It's fairly easy to convert timestamps to formatted dates. PHP handles this feature very well. Link to comment https://forums.phpfreaks.com/topic/137586-order-by-date/#findComment-719153 Share on other sites More sharing options...
limitphp Posted December 18, 2008 Author Share Posted December 18, 2008 Should all dates in timestamp have a time as well as the date? If they don't will that cause a problem? Link to comment https://forums.phpfreaks.com/topic/137586-order-by-date/#findComment-719163 Share on other sites More sharing options...
Jabop Posted December 18, 2008 Share Posted December 18, 2008 Should all dates in timestamp have a time as well as the date? If they don't will that cause a problem? timestamp has a date and time Link to comment https://forums.phpfreaks.com/topic/137586-order-by-date/#findComment-719164 Share on other sites More sharing options...
Maq Posted December 18, 2008 Share Posted December 18, 2008 Do some research!!!! TIMESTAMP columns are displayed in the same format as DATETIME columns. In other words, the display width is fixed at 19 characters, and the format is 'YYYY-MM-DD HH:MM:SS'. Link to comment https://forums.phpfreaks.com/topic/137586-order-by-date/#findComment-719167 Share on other sites More sharing options...
limitphp Posted December 18, 2008 Author Share Posted December 18, 2008 What is the difference in timestamp and datetime? Link to comment https://forums.phpfreaks.com/topic/137586-order-by-date/#findComment-719168 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.