phpSensei Posted October 1, 2007 Share Posted October 1, 2007 I have a time stamp in a phpbb table called topic_time $query1 = "Select * FROM phpbb_topics WHERE forum_id = 1 ORDER BY topic_time ASC LIMIT 3 "; How would I convert that topic_time timestamp to a real date from the query? ex: $query1 = "Select * FROM phpbb_topics WHERE forum_id = 1 ORDER BY ".date("Y M D", "topic_time"). "ASC LIMIT 3 "; doesnt seem to work though. Quote Link to comment https://forums.phpfreaks.com/topic/71310-convert-time-from-query/ Share on other sites More sharing options...
AndyB Posted October 1, 2007 Share Posted October 1, 2007 What is topic_time and why would sorting on topic_time give any different results from sorting on a 'real date' constructed from topic_time? Quote Link to comment https://forums.phpfreaks.com/topic/71310-convert-time-from-query/#findComment-358795 Share on other sites More sharing options...
phpSensei Posted October 1, 2007 Author Share Posted October 1, 2007 it is in the phpbb table for the time the topic was posted. I am taking all the topics from the news forum (which is id 1 ) and displaying it on the frontpage, but topic_time is a timestamp, and I want to convert it into a date in the query, so it is ordered by the date. Quote Link to comment https://forums.phpfreaks.com/topic/71310-convert-time-from-query/#findComment-358961 Share on other sites More sharing options...
MrManager Posted October 1, 2007 Share Posted October 1, 2007 The second query won't work because you can't use PHP functions on MySQL fields like that. But if it's a timestamp the first query should work fine anyway. To convert the date to your own format in the result, use the DATE_FORMAT function from MySQL. Quote Link to comment https://forums.phpfreaks.com/topic/71310-convert-time-from-query/#findComment-358965 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.