SQL Server 2005 Using DateAdd to Add a Day to a Date

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

+63
date sql sql-server tsql dateadd
03 Oct '08 at 15:42
source share
6 answers

Use the following function:

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

  • The value is the integer value you want to add (or subtract if you specify a negative number)

  • the type is one of:

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

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

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

+120
03 Oct '08 at 15:51
source share
 DECLARE @MyDate datetime -- ... set your datetime initial value ...' DATEADD(d, 1, @MyDate) 
+22
Oct 03 '08 at 15:44
source share

Try entering the following code: Add one day to the current date

 select DateAdd(day, 1, GetDate()) 

And in the same way you can use Year, Month, Hour, Second, etc. instead of a day in the same function

+13
Mar 03 '14 at 13:25
source share

The following query I used in SQL Server 2008 may help you.

 For add day DATEADD(DAY,20,GETDATE()) 

* 20 - the value of the day

Click here for more details.

+7
Oct 25 '13 at 12:54 on
source share
 DECLARE @date DateTime SET @date = GetDate() SET @date = DateAdd(day, 1, @date) SELECT @date 
+4
Oct 03 '08 at 15:45
source share
 Select getdate() -- 2010-02-05 10:03:44.527 -- To get all date format select CONVERT(VARCHAR(12),getdate(),100) +' '+ 'Date -100- MMM DD YYYY' -- Feb 5 2010 union select CONVERT(VARCHAR(10),getdate(),101) +' '+ 'Date -101- MM/DDYYYY' Union select CONVERT(VARCHAR(10),getdate(),102) +' '+ 'Date -102- YYYY.MM.DD' Union select CONVERT(VARCHAR(10),getdate(),103) +' '+ 'Date -103- DD/MM/YYYY' Union select CONVERT(VARCHAR(10),getdate(),104) +' '+ 'Date -104- DD.MM.YYYY' Union select CONVERT(VARCHAR(10),getdate(),105) +' '+ 'Date -105- DD-MM-YYYY' Union select CONVERT(VARCHAR(11),getdate(),106) +' '+ 'Date -106- DD MMM YYYY' --ex: 03 Jan 2007 Union select CONVERT(VARCHAR(12),getdate(),107) +' '+ 'Date -107- MMM DD,YYYY' --ex: Jan 03, 2007 union select CONVERT(VARCHAR(12),getdate(),109) +' '+ 'Date -108- MMM DD YYYY' -- Feb 5 2010 union select CONVERT(VARCHAR(12),getdate(),110) +' '+ 'Date -110- MM-DD-YYYY' --02-05-2010 union select CONVERT(VARCHAR(10),getdate(),111) +' '+ 'Date -111- YYYY/MM/DD' union select CONVERT(VARCHAR(12),getdate(),112) +' '+ 'Date -112- YYYYMMDD' -- 20100205 union select CONVERT(VARCHAR(12),getdate(),113) +' '+ 'Date -113- DD MMM YYYY' -- 05 Feb 2010 SELECT convert(varchar, getdate(), 20) -- 2010-02-05 10:25:14 SELECT convert(varchar, getdate(), 23) -- 2010-02-05 SELECT convert(varchar, getdate(), 24) -- 10:24:20 SELECT convert(varchar, getdate(), 25) -- 2010-02-05 10:24:34.913 SELECT convert(varchar, getdate(), 21) -- 2010-02-05 10:25:02.990 ---================================== -- To get the time select CONVERT(VARCHAR(12),getdate(),108) +' '+ 'Date -108- HH:MM:SS' -- 10:05:53 select CONVERT(VARCHAR(12),getdate(),114) +' '+ 'Date -114- HH:MM:SS:MS' -- 10:09:46:223 SELECT convert(varchar, getdate(), 22) -- 02/05/10 10:23:11 AM ----============================================= SELECT getdate()+1 SELECT month(getdate())+1 SELECT year(getdate())+1 
+1
Feb 05 '10 at 2:43
source share



All Articles