开发者

How to get results greater than yesterday

I hav开发者_运维知识库e 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(NOW(), INTERVAL 1 DAY)


WHERE event_date > date(now()) - 1


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 event_date >= CURDATE()


SELECT * FROM tbl_name WHERE field_date > now()- interval 1 day;


what this one does is to select values from the first minute today until last minute today.

WHERE scheduled_start_timestamp >= date() AND scheduled_start_timestamp <= date() + 1
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜