petri_28 Posted February 7, 2009 Share Posted February 7, 2009 Hello! I have a following problem with my MySQL. I have a one table called news, and inside that table I have a two colums called time and subject. Time is for example 14:53 and subject is normal string .. If I would like to make a query which would retrieve last subjects from the last for example 10 minutes I have tried this query: Select subject from news where aika between 'select time(current_timestamp)' and 'select time(now()-interval 10 minute)' but it gives me a zero result set .. I think I cannot use that kind of "variables" to generate time , but How I am going to make that query then ? Help needed! Petri Quote Link to comment https://forums.phpfreaks.com/topic/144208-problems-with-my-mysql-query/ Share on other sites More sharing options...
Rykin Posted March 5, 2009 Share Posted March 5, 2009 Are you storing you time as a timestamp or as a string like "14:53"? Also what language are you working in? I am mostly a PHP guy so I would do it like this (not saying this code will work but it will hopefully help point you in the right direction): $current = time(); $currentLessTen = $current - 600; $query = 'SELECT subject FROM news WHERE time BETWEEN ' . $currentLessTen . ' AND ' . $current . ' ORDER BY time DESC'; "ORDER BY time DESC" assumes you want the results listed from newest to oldest. Quote Link to comment https://forums.phpfreaks.com/topic/144208-problems-with-my-mysql-query/#findComment-777093 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.