Query SQL statement with date added
This is an SQL statement about the date added to the MSSQL access, which provides a large number of functions for the database tutorial date operation, and today our date is added using the DateAdd function for instance.
*/
Method one stored procedure
SET NOCOUNT ON
declare @kp table ([id] int,[ys] int,[syrq] datetime)
Insert @kp
Select 1,2, ' 2008-08-08 ' UNION ALL
Select 2,3, ' 2008-09-01 ' UNION ALL
Select 3, 33, ' 2008-08-11 '
Select Id,dateadd (MONTH,YS,SYRQ) as Syrq from @kp
Method two simple query statements
Select DATEADD (Month,cast (ys as int), SYRQ) as new date from KP
Method three DateAdd function date add
DATEADD (d,5, "2008-08-08")
DATEADD (d,5, "2008-08-08")
Sqlstr= "SELECT * from table where Time field =dateadd (d,5, ' 2008-08-08 ')"
Select DATEADD (D,5,cast (' 2008-08-08 ' as DateTime))
Select cast (' 2008-08-08 ' as datetime)
2008-08-13 00:00:00.000
2008-08-08 00:00:00.000
See a date Add SQL instance
Use pubs
Go
Select DATEADD (Day, pubdate) as timeframe
From titles
Go
/*
DateAdd function returns
Returns a Variant (date) that contains a date, plus a time interval.
Grammar
DATEADD (interval, number, date)
The following named arguments are in the DATEADD function syntax:
Partial description
Interval necessary. string expression, which is the time interval you want to add.
Number is necessary. Numeric expression, which is the number of time intervals to add. The value can be positive (get a future date), or it can be negative (get past date).
Date necessary. Variant (date) or text that represents a date, plus a time interval.
Set up
The interval parameter has the following set values:
Set description
YYYY the number of days of the year Q-m-month y
D-Day W week days WW week HH when n minutes s sec
*/