In
this article I am going to explain Dateadd function of Sql server.
In
previous article I have explained how to number of Tables, Views, Storeprocedures and Triggers in a sql server database, how to read XML file anddisplay data using asp.net MVC and how to export table to Excel file usingAngularjs in asp.net MVC.
Description:
Dateadd
function of sql server is used to add or subtract date and time.
Syntax:
dateadd(date/timeinterval,number,date)
Unit of date
|
Info
|
Day,dd,d,dy,y
|
Day
|
Month,mm,m
|
Month
|
Year,yy,yyyy
|
Year
|
Quarter,qq,q
|
Quarter
|
Week,wk,ww
|
Week
|
Unit of time
|
Info
|
Hour,hh
|
Hour
|
Minute,mi,n
|
Minute
|
Second,ss,s
|
Second
|
Millisecond,ms
|
Millisecond
|
Implementation:
Example add day:
declare @date date = getdate()
declare @dateadd date = dateadd(day,7,getdate())
select @dateadd as 'day added'
Output:
day added
|
2017-04-05
|
Example subtract day:
declare @date datetime
= getdate()
declare @dateadd datetime
= dateadd(dd,-7,getdate())
select @dateadd as 'day Subtract'
Output:
Day
subtract
|
2017-03-22
12:41:40.553
|
No comments:
Post a Comment