suttercain Posted September 14, 2007 Share Posted September 14, 2007 Hi everyone, I am so tried but can someone help and show me a basic way to only display the last twelve hours of results from the MySQL? I have a column with the time, how do I only show the last tweleve hours? strtotime? Link to comment https://forums.phpfreaks.com/topic/69294-last-twelve-hours-echoed-from-mysql/ Share on other sites More sharing options...
Kurrel Posted September 14, 2007 Share Posted September 14, 2007 What format is your time stored in the column? Link to comment https://forums.phpfreaks.com/topic/69294-last-twelve-hours-echoed-from-mysql/#findComment-348203 Share on other sites More sharing options...
suttercain Posted September 14, 2007 Author Share Posted September 14, 2007 MySQL default HH:MM:SS = 24:12:12 Link to comment https://forums.phpfreaks.com/topic/69294-last-twelve-hours-echoed-from-mysql/#findComment-348213 Share on other sites More sharing options...
redarrow Posted September 14, 2007 Share Posted September 14, 2007 somethink like that not sure theo. SELECT * from x where x = HOUR('$x', INTERVAL - 12 HOUR); Link to comment https://forums.phpfreaks.com/topic/69294-last-twelve-hours-echoed-from-mysql/#findComment-348218 Share on other sites More sharing options...
suttercain Posted September 14, 2007 Author Share Posted September 14, 2007 MySQL server version for the right syntax to use near ' INTERVAL -12 HOUR)' at line 1 : ( $sql = mysql_query("SELECT * FROM latestGreatest WHERE latestTime = HOUR('".$time."', INTERVAL -12 HOUR)") or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/69294-last-twelve-hours-echoed-from-mysql/#findComment-348221 Share on other sites More sharing options...
redarrow Posted September 14, 2007 Share Posted September 14, 2007 TRY THIS PLEASE. mysql_query("SELECT * FROM latestGreatest WHERE latestTime = DATE_SUB('".$time."', INTERVAL 12 HOUR)") or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/69294-last-twelve-hours-echoed-from-mysql/#findComment-348228 Share on other sites More sharing options...
suttercain Posted September 14, 2007 Author Share Posted September 14, 2007 I didn't get an error... that mean it worked? Thanks! Link to comment https://forums.phpfreaks.com/topic/69294-last-twelve-hours-echoed-from-mysql/#findComment-348229 Share on other sites More sharing options...
jitesh Posted September 14, 2007 Share Posted September 14, 2007 SELECT * from table WHERE `feildname` between (CURRENT_TIMESTAMP()) AND (CURRENT_TIMESTAMP() - INTERVAL 12 HOUR) Link to comment https://forums.phpfreaks.com/topic/69294-last-twelve-hours-echoed-from-mysql/#findComment-348242 Share on other sites More sharing options...
suttercain Posted September 14, 2007 Author Share Posted September 14, 2007 Hi Jtesh, I gave it a shot and I am getting back no results, even though I do have an update within the last hour... Link to comment https://forums.phpfreaks.com/topic/69294-last-twelve-hours-echoed-from-mysql/#findComment-348521 Share on other sites More sharing options...
suttercain Posted September 14, 2007 Author Share Posted September 14, 2007 Can I do this just useing a TIME field or must I use a TIMEDATE or something else? Thanks. SC Link to comment https://forums.phpfreaks.com/topic/69294-last-twelve-hours-echoed-from-mysql/#findComment-348525 Share on other sites More sharing options...
suttercain Posted September 14, 2007 Author Share Posted September 14, 2007 I switched over time a timestamp to test out this code $sql = mysql_query("SELECT * FROM latestGreatest WHERE `latestTimeStamp` between (CURRENT_TIMESTAMP()) AND (CURRENT_TIMESTAMP() - INTERVAL 12 HOUR)") or die(mysql_error()); $total = mysql_num_rows($sql); echo "$total"; I am still getting zero number of rows, but there should be two. Any advice? Thanks Link to comment https://forums.phpfreaks.com/topic/69294-last-twelve-hours-echoed-from-mysql/#findComment-348543 Share on other sites More sharing options...
jitesh Posted September 15, 2007 Share Posted September 15, 2007 SELECT * FROM DATA WHERE `timefeield` < CURRENT_TIMESTAMP( ) AND `Name` > ( CURRENT_TIMESTAMP( ) - INTERVAL 12 HOUR ) Link to comment https://forums.phpfreaks.com/topic/69294-last-twelve-hours-echoed-from-mysql/#findComment-348850 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.