waynew Posted August 31, 2008 Share Posted August 31, 2008 I've been building a custom forum and my DB tables look like so: <?php mysql_query( "CREATE TABLE thread( thread_id BIGINT(50) NOT NULL AUTO_INCREMENT, user_started BIGINT(50) NOT NULL, title TEXT NOT NULL, body TEXT NOT NULL, last_post_time DATETIME NOT NULL, latest_poster_id BIGINT(50) NOT NULL, PRIMARY KEY(thread_id))") or die(mysql_error()); mysql_query( "CREATE TABLE thread_post( thread_post_id BIGINT(50) NOT NULL AUTO_INCREMENT, parent_thread_id BIGINT(50) NOT NULL, user_posting BIGINT(50) NOT NULL, time_posted DATETIME NOT NULL, body TEXT NOT NULL, PRIMARY KEY(thread_post_id))") or die(mysql_error()); ?> When you go to the forum main page, all forum topics are ordered by last_post_time, which is a DATETIME value. The query looks like so: <?php function get_topics_listing(){ $select = mysql_query("SELECT thread_id,title,user_started,latest_poster_id,last_post_time FROM thread ORDER BY last_post_time DESC LIMIT 30") or die(mysql_error()); return $select; } ?> This seemed to be working fine until today when a topic with the last post time of 2008-08-31 12:40:29 came out above another newer topic with the last post time of 2008-08-31 01:52:54 Why would this be? Cheers for the help. Link to comment https://forums.phpfreaks.com/topic/122101-datetime-problem/ Share on other sites More sharing options...
Guardian-Mage Posted August 31, 2008 Share Posted August 31, 2008 For that to work right the time must be in 24 hour format. The two dates you gave, the first one 2008-08-31 12:40:29 is newer than 2008-08-31 01:52:54. With 24 hour time,the two dates would be: 2008-08-31 12:40:29 2008-08-31 13:52:54 Link to comment https://forums.phpfreaks.com/topic/122101-datetime-problem/#findComment-630383 Share on other sites More sharing options...
waynew Posted August 31, 2008 Author Share Posted August 31, 2008 Thanks! I had just noticed that believe it or not. I'll just fix how I create the date. Thanks! Link to comment https://forums.phpfreaks.com/topic/122101-datetime-problem/#findComment-630386 Share on other sites More sharing options...
waynew Posted August 31, 2008 Author Share Posted August 31, 2008 <?php $date_time = date("Y-m-d")." ".date("H:i:s"); ?> Fixed. Thanks. Link to comment https://forums.phpfreaks.com/topic/122101-datetime-problem/#findComment-630388 Share on other sites More sharing options...
Guardian-Mage Posted September 2, 2008 Share Posted September 2, 2008 Don't forget to mark it as solved Link to comment https://forums.phpfreaks.com/topic/122101-datetime-problem/#findComment-631963 Share on other sites More sharing options...
discomatt Posted September 2, 2008 Share Posted September 2, 2008 <?php $date_time = date("Y-m-d")." ".date("H:i:s"); ?> Fixed. Thanks. Durrr <?php $date_time = date("Y-m-d H:i:s"); ?> Link to comment https://forums.phpfreaks.com/topic/122101-datetime-problem/#findComment-631976 Share on other sites More sharing options...
PFMaBiSmAd Posted September 2, 2008 Share Posted September 2, 2008 Using the mysql now() function directly in the query would be many times faster as the php date() function is fairly slow (and calling it twice is causing php to take twice as long.) Link to comment https://forums.phpfreaks.com/topic/122101-datetime-problem/#findComment-631983 Share on other sites More sharing options...
discomatt Posted September 2, 2008 Share Posted September 2, 2008 Agreed. I usually create my self-generating date columns like this ADD `date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP Link to comment https://forums.phpfreaks.com/topic/122101-datetime-problem/#findComment-632007 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.