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
/*
The DATEADD function returns a Variant (date) that contains a date, plus a time interval. The syntax DateAdd (interval, number, date) has the following named parameters 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. Setting the interval parameter has the following set of values: Set description yyyy year Q quarter m month Y the day of the year D-Day of the week in the days of WW week hh N minutes S seconds
*/