SQL SERVER: Dateadd function | ASPMANTRA | Asp.Net,MVC,AngularJs,Jquery,Javascript,Sql Server AND WCF snippets and tutorial

SQL SERVER: Dateadd function

In this article I am going to explain Dateadd function of Sql server.


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


Post a Comment

[blogger]

MKRdezign

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget