How to add days months or years to date using DateAdd function SQL Server

Опубликовано: 10 Сентябрь 2017
на канале: Learn 2 Excel
4,525
12

Published on Sep 10, 2017:
In this video tutorial, we will learn to add subtract days,months, quarters and years from any given date.
We can use the same logic for other date parts mentioned in the Microsoft documentation.
Link to the microsoft documentation
https://goo.gl/7M8Yjc

Example 1 SQL Used:
Select getdate()
,DateAdd(day,10,getdate())DayAdd --Add Day(s)
,DateAdd(day,-10,getdate())DaySubtract --Subtract Day(s)
, DateAdd(month,1,getdate())MonthAdd--Add Month(s)
,DateAdd(month,-1,getdate())MonthSubtract--Subtract Month(s)
,DateAdd(year,1,getdate())YearAdd--Add Year(s)
,DateAdd(year,-1,getdate())YearSubtract--Subtract Year(s)

Example 2 SQL Used:

SELECT
[FullDateAlternateKey]
,DateAdd(day,10,[FullDateAlternateKey])DayAdd --Add Day(s)
,DateAdd(day,-10,[FullDateAlternateKey])DaySubtract --Subtract Day(s)
, DateAdd(month,1,[FullDateAlternateKey])MonthAdd--Add Month(s)
,DateAdd(month,-1,[FullDateAlternateKey])MonthSubtract--Subtract Month(s)
,DateAdd(year,1,[FullDateAlternateKey])YearAdd--Add Year(s)
,DateAdd(year,-1,[FullDateAlternateKey])YearSubtract--Subtract Year(s)
FROM [AdventureWorksDW2012].[dbo].[DimDate]

Previous Video:   • HeatMap Power BI  

SUBSCRIBE to learn more about Power BI,Power Query, Power Pivot, Excel and SQL Server!
   / @learnexcelrelentless  



Download the sample database used for the demo here: https://goo.gl/SVyVmT

Our Playists:
SQL Playlist :https://goo.gl/PS5Ep6
DAX PlayList : https://goo.gl/S4W41D
Power BI PlayList: https://goo.gl/dXxvnB
Power Query Playlist: https://goo.gl/5QS7P4


ABOUT DAGDOO:
Website:
Home Page: http://www.dagdoo.org/
Power BI Tutorials: http://www.dagdoo.org/excel-learning/...


Questions? Comments and SUGESTIONS? You will find me here:

Twitter: @dagdooe

Category: Science & Technology
License: Standard YouTube License