refiking Posted January 23, 2009 Share Posted January 23, 2009 I need the query to check for records that were updated within the last 5 days. How can I add that to this script? //datetime_last_updated is the field that I need to check to see if it was updated in the last 5 days $result = mysql_query("SELECT * FROM heap ORDER BY datetime_last_updated ASC LIMIT $limit ")or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/142133-solved-need-to-search-db-based-on-last-5-days/ Share on other sites More sharing options...
gevans Posted January 23, 2009 Share Posted January 23, 2009 what is the format of datetime_last_updated? Link to comment https://forums.phpfreaks.com/topic/142133-solved-need-to-search-db-based-on-last-5-days/#findComment-744470 Share on other sites More sharing options...
refiking Posted January 23, 2009 Author Share Posted January 23, 2009 timestamp Link to comment https://forums.phpfreaks.com/topic/142133-solved-need-to-search-db-based-on-last-5-days/#findComment-744471 Share on other sites More sharing options...
flyhoney Posted January 23, 2009 Share Posted January 23, 2009 Try this: SELECT * FROM heap WHERE date_time_last_updated >= FROM_UNIXTIME(".mktime(0, 0, 0, date("m"), date("d") - 5, date("Y"))." ORDER BY datetime_last_updated ASC LIMIT $limit Link to comment https://forums.phpfreaks.com/topic/142133-solved-need-to-search-db-based-on-last-5-days/#findComment-744473 Share on other sites More sharing options...
gevans Posted January 23, 2009 Share Posted January 23, 2009 <?php $five_days = (60*60*24*5); $five_days_ago = time() - $five_days; //query to be done after db connection $query = "SELECT * FROM heap WHERE datetime_last_updated > $five_days_ago"; $result = mysql_query($query)or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/142133-solved-need-to-search-db-based-on-last-5-days/#findComment-744474 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.