views:

306

answers:

5

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

+4  A: 
SELECT DATEADD(day, 180, getdate())
Yada
+7  A: 
DATEADD(d, 180, GetDate())
Graham Clark
+1  A: 
getdate() + 180

for example:

select getdate() as Today, getdate() + 180 as About6MonthsLater
RedFilter
I am currently struggling the dates
Kip Birgen
@Kip: I don't understand what you mean.
RedFilter
+1, what I was thinking. In SQL Server you can use addition and subtraction on DATETIMEs in day increments, with no need for DATEADD()
KM
A: 

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))
Raj More
Why use varchar to chop time? It's locale dependent and inefficient.
gbn
A: 

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)
gbn