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 https://forums.phpfreaks.com/topic/278935-query-change-from-hour-ro-minute/ 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 https://forums.phpfreaks.com/topic/278935-query-change-from-hour-ro-minute/#findComment-1434859 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 https://forums.phpfreaks.com/topic/278935-query-change-from-hour-ro-minute/#findComment-1434878 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 https://forums.phpfreaks.com/topic/278935-query-change-from-hour-ro-minute/#findComment-1434879 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 https://forums.phpfreaks.com/topic/278935-query-change-from-hour-ro-minute/#findComment-1434882 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 https://forums.phpfreaks.com/topic/278935-query-change-from-hour-ro-minute/#findComment-1434883 Share on other sites More sharing options...
dweb Posted June 8, 2013 Author Share Posted June 8, 2013 Awesome thanks Quote Link to comment https://forums.phpfreaks.com/topic/278935-query-change-from-hour-ro-minute/#findComment-1434885 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.