简体   繁体   中英

How to get data out of a database where the saved date is greater than another date + 1 week

I wanna get all my articles out of my database where the date of the last update is greater than the publishing date + 1 week.

Do you habe an idea how that should work? In my table there is the publish_date and the update_date . Both of them contain a datetime in the following format: Ymd H:i:s

It should be something like the following (which does not work!)

SELECT * FROM foo WHERE update_date > publish_date+1week
SELECT * FROM foo WHERE update_date > DATE_ADD(publish_date, INTERVAL 1 WEEK)

参见MySQL DATE_ADD

如果您想保留自己的结构(即不使用DATE_ADD函数),则可以使用:

SELECT * FROM foo WHERE update_date > publish_date + INTERVAL 1 WEEK

You can use DATEADD() function to add weeks to DateTime in Sql Server. DATEADD() functions first parameter value can be week or wk or ww, all will return the same result.

SELECT GETDATE() 'Today', DATEADD(week,1,GETDATE())'Today + 1 Week'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM