shlomikalfa Posted May 24, 2008 Share Posted May 24, 2008 hey guys, i've been wandering how do i extract from a MySQL table only those entries which their time has passed $X time.... I.E. [table][tr][td] Entry 1 - Date1 Entry 2 - Date2 I want to make a MySQL Query which will return only those entries which their Date is older then 160 Seconds... How do i do that ? SELECT `ID` FROM `MyTable` WHERE TIMESTAMPDIFF(SECOND,`TimeStamp`,NOW()) > 160 The above seems to fail! Link to comment https://forums.phpfreaks.com/topic/107044-solved-how-do-i-get-only-the-entrys-which-passed-x-time-mysqlphp/ Share on other sites More sharing options...
beboo002 Posted May 24, 2008 Share Posted May 24, 2008 use unix timestamp with now() and less 160 to get 160 sec older record Link to comment https://forums.phpfreaks.com/topic/107044-solved-how-do-i-get-only-the-entrys-which-passed-x-time-mysqlphp/#findComment-548738 Share on other sites More sharing options...
shlomikalfa Posted May 24, 2008 Author Share Posted May 24, 2008 well... this is taken directly from the MySQL references: SELECT `ID` FROM `MyTable` WHERE DATE_SUB(CURDATE(),INTERVAL 500 SECOND) >= `TimeStamp`; and yet it doesn't work.... even if i manualy copy the timestamp value from the table ie. "2008-05-22 12:33:28" It always gives me either all results or none.... regardless the timestamp from the table. Link to comment https://forums.phpfreaks.com/topic/107044-solved-how-do-i-get-only-the-entrys-which-passed-x-time-mysqlphp/#findComment-548739 Share on other sites More sharing options...
shlomikalfa Posted May 24, 2008 Author Share Posted May 24, 2008 Well, it took me a couple of tries to realize what you meant.... that was to take the time() via php prior to the MySQL call... that works perfectly !!! $sql = 'SELECT `ID` FROM `MyTable` WHERE `TimeStamp` <= "'.(time()-160).'";'; $result = mysql_query($sql, $link); if (!$result) {die('#1 Error: ' . mysql_error());} while($row = mysql_fetch_assoc($result)){ echo $row['ID']."|"; } [move]Thanks a lot mate !!![/move] Link to comment https://forums.phpfreaks.com/topic/107044-solved-how-do-i-get-only-the-entrys-which-passed-x-time-mysqlphp/#findComment-548742 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.