In this article I will explain how to use DATEADD function to add or subtract specified time interval from dates in SQL Server.
DATEADD (datepart, number, date)
|
datepart
|
Abbreviation
|
year
|
yy, yyyy
|
quarter
|
qq, q
|
month
|
mm, m
|
dayofyear
|
dy, y
|
day
|
dd, d
|
week
|
wk, ww
|
weekday
|
dw, w
|
hour
|
hh
|
minute
|
mi, n
|
second
|
ss, s
|
millisecond
|
ms
|
microsecond
|
mcs
|
nanosecond
|
ns
|
SELECT GETDATE() AS CurrentDate,DATEADD (mm, 1, GETDATE()) AS NewDate
|
CurrentDate
|
NewDate
|
2012-10-31 03:10:19.457
|
2012-11-30 03:10:19.457
|
SELECT GETDATE() AS CurrentDate,DATEADD (mm, -1, GETDATE()) AS NewDate
|
CurrentDate
|
NewDate
|
2012-10-31 03:14:30.200
|
2012-09-30 03:14:30.200
|
OrderId
|
OrderName
|
ShippingDate
|
1
|
Aspdotnet-Suresh Book
|
2012-10-31 03:44:00.053
|
SELECT OrderId,
OrderName, DATEADD(dd,15,ShippingDate) As ShippingDate FROM
Orders
|
OrderId
|
OrderName
|
ShippingDate
|
1
|
Aspdotnet-Suresh Book
|
2012-11-15 03:44:00.053
|
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
Subscribe by RSS
Subscribe by Email
|
|||
|
|
Subscribe by RSS
Subscribe by Email
2 comments :
hi suresh ji! you r doing great job.thanks for you articles.
sir,its my request to u ,please teach us MVC and WCF.
highly thankful to you
Vipin Kumar Pandey
Sir,it is great Sir can you please guide me the technique regarding "Password Encryption with Salt values" so that even a hacker cannot able to decrypt it with the help of any decryption Algorithm
As always I told your work will oneday proved to be as a "Mother of ASP.NET learners"