How to determine dat开发者_如何学编程es by number of days from now - "What date is 180 days from now?"
DATEADD(d, 180, GetDate())
SELECT DATEADD(day, 180, getdate())
getdate() + 180
for example:
select getdate() as Today, getdate() + 180 as About6MonthsLater
Since you just want the date, the time part should be stripped out after the calculation is done.
SELECT CONVERT (DATETIME, CONVERT (VARCHAR (20), DATEADD(d, 180, GetDate()), 101))
To find 180 days ahead and remove the time component in one easy go.
No relying on internal implementation (using +) or string handling to chop time.
SELECT DATEADD(day, DATEDIFF(day, 0, GETDATE()), 180)
精彩评论