MySQL DATE_ADD usage, 5 day interval

我们两清 提交于 2019-12-01 15:08:11

To get records between a date span, use:

WHERE created BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL 5 DAY)

This example will get you records (assuming any exist for today, including time) for between today and days into the future. Look at DATE_SUB if you want to go into the past.

afaaro

If your created column type is int then just try this one

created<= UNIX_TIMESTAMP(DATE_ADD(CURDATE(),INTERVAL 5 DAY))')
WHERE created <= NOW() AND created >=NOW() - INTERVAL 5 DAY

or it would be better to compare just DATE part of datetime:

WHERE DATE(created) <= date(NOW()) AND 
  DATE(created) >= DATE(NOW() - INTERVAL 5 DAY)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!