dweb Posted June 8, 2013 Share Posted June 8, 2013 (edited) Hi everyone I have this Query SELECT *, IF(HOUR(TIMEDIFF(NOW(), datetime)) >= 1, 1, 0) AS OlderThanAnHour FROM people_and_staff Which works great, and shows me all the records in the last hour How can I alter this to show me records in the last 3 minutes? Thank you Edited June 8, 2013 by dweb Quote Link to comment Share on other sites More sharing options...
Barand Posted June 8, 2013 Share Posted June 8, 2013 Search for rows WHERE datetime BETWEEN NOW() - INTERVAL 3 MINUTE AND NOW() Quote Link to comment Share on other sites More sharing options...
dweb Posted June 8, 2013 Author Share Posted June 8, 2013 Sorry, my mistake I don't want to just show the ones in the last hour i want to set the value 'OlderThanAnHour' to 0 if the record was added in the last 3 mins, and 1 if the record was added later than 3 mins ago Is that possible by altering my Query a little? Quote Link to comment Share on other sites More sharing options...
DaveyK Posted June 8, 2013 Share Posted June 8, 2013 You could do a case, but why not process it in your code Quote Link to comment Share on other sites More sharing options...
dweb Posted June 8, 2013 Author Share Posted June 8, 2013 Someone said it was faster to do it in the Query than in code, but i'll take your advice, thanks Quote Link to comment Share on other sites More sharing options...
Solution Barand Posted June 8, 2013 Solution Share Posted June 8, 2013 SELECT IF(datetime BETWEEN NOW() - INTERVAL 3 MINUTE AND NOW(), 0, 1) as olderThan3mins ... Quote Link to comment Share on other sites More sharing options...
dweb Posted June 8, 2013 Author Share Posted June 8, 2013 Awesome thanks Quote Link to comment 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.