Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server 2005 Using DateAdd to add a day to a date

How do I in SQL Server 2005 use the DateAdd function to add a day to a date

like image 560
test Avatar asked Oct 03 '08 15:10

test


People also ask

How can I add one day to a date in SQL query?

SQL Server DATEADD() Function The DATEADD() function adds a time/date interval to a date and then returns the date.

Does Dateadd work with datetime?

DATEADD does not allow addition for a datepart of microsecond or nanosecond for date data types smalldatetime, date, and datetime.


1 Answers

Use the following function:

DATEADD(type, value, date) 
  • date is the date you want to manipulate

  • value is the integere value you want to add (or subtract if you provide a negative number)

  • type is one of:

    • yy, yyyy: year
    • qq, q: quarter
    • mm, m: month
    • dy, y: day of year
    • dd, d: day
    • wk, ww: week
    • dw, w: weekday
    • hh: hour
    • mi, n: minute
    • ss or s: second
    • ms: millisecond
    • mcs: microsecond
    • ns: nanosecond

SELECT DATEADD(dd, 1, GETDATE()) will return a current date + 1 day

http://msdn.microsoft.com/en-us/library/ms186819.aspx

like image 188
Ilya Kochetov Avatar answered Sep 19 '22 17:09

Ilya Kochetov