EchoFool Posted January 9, 2009 Share Posted January 9, 2009 I have a time stamp in a query that i want to create which only updates rows where by the time stamp is 20 minutes or greater than from Now() in the passed... in other words 20 minutes or more has passed since that timestamp was created. But i don't know how to do it ? This is what im aiming to do: DELETE FROM users WHERE `TimeStamp` compared to NOW() is 20 minutes or more.") Quote Link to comment https://forums.phpfreaks.com/topic/140196-solved-help-with-passed-20-minutes-query/ Share on other sites More sharing options...
xtopolis Posted January 9, 2009 Share Posted January 9, 2009 Read here: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html Quote Link to comment https://forums.phpfreaks.com/topic/140196-solved-help-with-passed-20-minutes-query/#findComment-733658 Share on other sites More sharing options...
EchoFool Posted January 9, 2009 Author Share Posted January 9, 2009 I don't see a compare function in that list, i saw that list before posting.. is there no compare function set in mysql? Quote Link to comment https://forums.phpfreaks.com/topic/140196-solved-help-with-passed-20-minutes-query/#findComment-733701 Share on other sites More sharing options...
corbin Posted January 9, 2009 Share Posted January 9, 2009 http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-sub Quote Link to comment https://forums.phpfreaks.com/topic/140196-solved-help-with-passed-20-minutes-query/#findComment-733712 Share on other sites More sharing options...
EchoFool Posted January 10, 2009 Author Share Posted January 10, 2009 So sumin like: Field = timestamp field in database WHERE (DAY_MINUTE,Field) > 20 ??? right? Quote Link to comment https://forums.phpfreaks.com/topic/140196-solved-help-with-passed-20-minutes-query/#findComment-733774 Share on other sites More sharing options...
xtopolis Posted January 10, 2009 Share Posted January 10, 2009 So sumin like: Field = timestamp field in database WHERE (DAY_MINUTE,Field) > 20 ??? right? That doesn't make sense. If I inserted a row into your query at 2009-01-09 13:22:00 (Jan 9th, 2009 at 1:22pm) and you ran your script at 1:23pm .. it would delete my row even though 20 minutes hadn't passed. You want to use the DATE_SUB() function which would look like this: SELECT `TimeStamp` FROM users WHERE `TimeStamp` <= DATE_SUB(NOW(), INTERVAL 20 MINUTE) Test is with a select before actually trying to delete anything! Make sure it returns the rows you intend for it to delete The DATE_SUB() function means: Subtract 20 minutes from NOW, then select anything that is less than(before) or equal to that time. Obviously if it's from before, it's older than 20 minutes. Also, it is recommended to rename your column name "TimeStamp" because it is using a reserved word. Quote Link to comment https://forums.phpfreaks.com/topic/140196-solved-help-with-passed-20-minutes-query/#findComment-733782 Share on other sites More sharing options...
EchoFool Posted January 10, 2009 Author Share Posted January 10, 2009 Thank you ! Works a treat Quote Link to comment https://forums.phpfreaks.com/topic/140196-solved-help-with-passed-20-minutes-query/#findComment-734049 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.