moto51 Posted October 10, 2011 Share Posted October 10, 2011 I have a database that inserts a record every 5 minutes, 24/7. I want to easily retrieve the closest record to the current time - 1 day. Could somebody point me into the right direction please. Link to comment https://forums.phpfreaks.com/topic/248786-select-record-closest-to-this-time-yesterday/ Share on other sites More sharing options...
moto51 Posted October 10, 2011 Author Share Posted October 10, 2011 Solved it, used PHP as I had to use it anyway. function minutes_round ($hour, $minutes = '5', $format = "H:i") { $seconds = strtotime($hour); $rounded = round($seconds / ($minutes * 60)) * ($minutes * 60); return date($format, $rounded); } $yesterdayDate = date("Y-m-d", mktime(0, 0, 0, date("m"),date("d")-1,date("Y"))); $time = date( 'H:i:s'); $time = minutes_round($time); Link to comment https://forums.phpfreaks.com/topic/248786-select-record-closest-to-this-time-yesterday/#findComment-1277659 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.