Jump to content

[SOLVED] how do i get only the entrys which passed $X time ?! [MySQL+PHP].


shlomikalfa

Recommended Posts

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!

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.

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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.