简体   繁体   中英

Select * Where Date 1 and Date 2 elapsed time is greater than

I have 2 Columns in the same table: CREATED DATE and APPROVED DATE

In my Select statement, I would like to return only records Where the elapsed time between CREATED DATE and APPROVED DATE is greater than 2 days, or where the APPROVED DATE is greater than CREATED DATE by 2 days.

I really appreciate the help!

您可以使用DATEDIFF

WHERE DATEDIFF(created_date, approved_date) > 2 OR DATEDIFF(approved_date, created_date) > 2

Depending on how precisely you need to know:

If the "date" columns are dates:

WHERE DATEDIFF(`APPROVED DATE`, `CREATED DATE`) > 2

If the "date" columns are timestamps and you want to know the second 2 days have passed:

WHERE TIMESTAMPDIFF(DAY, `CREATED DATE`, `APPROVED DATE`) > 2

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