jwk811 Posted February 22, 2010 Share Posted February 22, 2010 $sql = "UPDATE message SET status = 'new' WHERE post_time < (x)"; i want it to change the status to 'new' for every message that was posted less than 30 minutes ago Link to comment https://forums.phpfreaks.com/topic/192986-update-where-time-30-minutes-ago/ Share on other sites More sharing options...
schilly Posted February 22, 2010 Share Posted February 22, 2010 what's the data type of post_time in that table? Link to comment https://forums.phpfreaks.com/topic/192986-update-where-time-30-minutes-ago/#findComment-1016348 Share on other sites More sharing options...
jwk811 Posted February 22, 2010 Author Share Posted February 22, 2010 datetime Link to comment https://forums.phpfreaks.com/topic/192986-update-where-time-30-minutes-ago/#findComment-1016350 Share on other sites More sharing options...
schilly Posted February 22, 2010 Share Posted February 22, 2010 try this $sql = "UPDATE message SET status = 'new' WHERE post_time >= FROM_UNIXTIME(" . time() - 60*30 . ") "; there should be a way directly in mysql but i'm not totally sure on the syntax. you can look at the date/time f'ns in mysql here: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html Link to comment https://forums.phpfreaks.com/topic/192986-update-where-time-30-minutes-ago/#findComment-1016367 Share on other sites More sharing options...
jwk811 Posted February 22, 2010 Author Share Posted February 22, 2010 uh didnt work. still all old Link to comment https://forums.phpfreaks.com/topic/192986-update-where-time-30-minutes-ago/#findComment-1016395 Share on other sites More sharing options...
schilly Posted February 22, 2010 Share Posted February 22, 2010 This should work too $sql = "UPDATE message SET status = 'new' WHERE post_time >= DATE_SUB(NOW(), INTERVAL 30 MINUTE) "; Did you try a select to see if it matched any rows? Link to comment https://forums.phpfreaks.com/topic/192986-update-where-time-30-minutes-ago/#findComment-1016427 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.