I have a database that stores the date for each entry with the DATETIME format. I need to only retrieve results that are greater than yesterday. I say yesterday because I need the results for the current day and forward.
Currently I have the following.
$yest = mktime(0, 0, 0, date("m"), date("d")-1, date("Y"));
$yest_date = date('n-j-o', $yest);
SELECT * FROM TBL_NAME WHERE DATE_FORMAT(event_date, \"%c-%d-%Y\") > '".$yest_date."'
That does not give any results even though I know there are events. Any help would be greatly appreciated.
Select * from tbl_name WHERE event_date > DATE_SUB(curdate(), INTERVAL 1 DAY)
This should have it start from the beginning of yesterday rather than 24hours back from the time the query is run.
If you have this run in a cron you should probably verify the timezone of the database vs the server so that you don't run it for two days back intending to run at 12:01 but actually running at 11:01 due to variance.
SELECT * FROM tbl_name WHERE field_date > now()- interval 1 day;
WHERE event_date > date(now()) - 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With