Determine dates by number of days, "which date is 180 days

How to determine the dates by the number of days from now - "What date is 180 days?"

+3
source share
5 answers
DATEADD(d, 180, GetDate())
+8
source
SELECT DATEADD(day, 180, getdate())
+4
source
getdate() + 180

eg:

select getdate() as Today, getdate() + 180 as About6MonthsLater
+1
source

Since you just need a date, part of the time should be deleted after the calculation is complete.

SELECT CONVERT (DATETIME, CONVERT (VARCHAR (20), DATEADD(d, 180, GetDate()), 101))
0
source

To find 180 days in advance and remove the time component at a time.

Do not rely on internal implementation (using +) or line processing to interrupt time.

SELECT DATEADD(day, DATEDIFF(day, 0, GETDATE()), 180)
0
source

Source: https://habr.com/ru/post/1734081/


All Articles