SQL statement for date addition Query
This is an SQL statement that describes the date addition of mssql access. It provides a large number of functions for database tutorial date operations. Today, we use the dateadd function to add dates.
*/
// Method 1 stored procedure
Set nocount on
Declare @ kp table ([id] int, [ys] int, [syrq] datetime)
Insert @ kp
Select 1, 2, '2017-08-08 'union all
Select 2, 3, '2014-09-01 'union all
Select 3, 33, '2017-08-11'
Select id, dateadd (month, ys, syrq) as syrq from @ kp
// Method 2 simple query statement
Select dateadd (month, cast (ys as int), syrq) as new date from kp
// Method 3 dateadd function date Addition
Dateadd (d, 5, "2008-08-08 ")
Dateadd (d, 5, "2008-08-08 ")
Sqlstr = "select * from table where time field = dateadd (d, 5, '2017-08-08 ')"
Select dateadd (d, 5, cast ('2017-08-08 'as datetime ))
Select cast ('2017-08-08 'as datetime)
2008-08-13 00:00:00. 000
2008-08-08 00:00:00. 000
Add SQL instances by date
Use pubs
Go
Select dateadd (day, 21, pubdate) as timeframe
From titles
Go
/*
Returns the dateadd function.
Returns the variant (date) that contains a date. This date is added with a time interval.
Syntax
Dateadd (interval, number, date)
The dateadd function syntax includes the following naming parameters:
Partial description
Interval is required. String expression, which is the time interval to be added.
Number is required. A numeric expression is the number of time intervals to be added. The value can be a positive number (to get the future date) or a negative number (to get the past date ).
Date is required. Variant (date) or text that represents the date, which is added with the time interval.
Set
The interval parameter has the following settings:
Set description
Yyyy Year q quarter m month y day of a year
D, w, the number of days in a week, ww, hh, n minutes, s seconds
*/