Some useful Date expressions for SSIS

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail
FacebooktwitterlinkedinrssyoutubeFacebooktwitterlinkedinrssyoutube

I engaged in creating some date expressions yesterday, these expressions are very common needed. So I bring them here to share.

Suppose your Date Field name is FillDt ,

1- number of days in the quarter of date field.

For example
                     If the fillDt is "2002-03-04" the count will be 63
                     If the fillDt is "2002-06-20" the count will be 81

expression:

DATEDIFF("DAY",(DT_DATE)(((DT_WSTR,4)YEAR(fillDt)) + "-" + ((DT_WSTR,2)(((DATEPART("QUARTER",fillDt) – 1) * 3) + 1)) + "-1"),fillDt)

2-

number of days in the year of date field.

For example
                     If the fillDt is "2002-03-04" the count will be 63
                     If the fillDt is "2002-06-20" the count will be 171

expressio
n:
DATEDIFF
("DAY",(DT_DATE)(((DT_WSTR,4)YEAR(fillDt)) + "-1-1"),fillDt)

3- Number of months of the quarter of date

For example:
                    If the fillDt is "2002-03-31" the count will be 3
                    If the fillDt is "2002-06-30" the count will be 3
                    If the fillDt is "2002-07-13" the count will be 1

ex
pression:
D
ATEDIFF("MONTH",(DT_DATE)(((DT_WSTR,4)YEAR(fillDt)) + "-" + ((DT_WSTR,2)(((DATEPART("QUARTER",fillDt) – 1) * 3) + 1)) + "-1"),fillDt)

4- quarter number of date

For example
                    If the fillDt is "2002-03-04" the quarter count will be 1
                    If the fillDt is "2002-06-20" the quarter count will be 2
                    If the fillDt is "2002-10-06" the quarter count will be 4

expressio
n:
(DT_WSTR
,1)(DATEPART("QUARTER",fillDt))


5- quarter start date

For example
                   If the fillDt is "2002-03-04" the "quarterStartDt" will be "2002-01-01"
                   If the fillDt is "2002-06-20" the "quarterStartDt" will be "2002-04-01"

exp
ression:
(D
T_DATE)(((DT_WSTR,4)YEAR(fillDt)) + "-" + ((DT_WSTR,2)(((DATEPART("QUARTER",fillDt) – 1) * 3) + 1)) + "-1")

6- quarter end date
For example
                   If the fillDt is "2002-03-04" the "quarterStopDt" will be "2002-03-31"
                   If the fillDt is "2002-06-20" the "quarterStopDt" will be "2002-06-30"

expression:
DATEA
DD("DAY",-1,DATEADD("MONTH",3,(DT_DATE)(((DT_WSTR,4)YEAR(fillDt)) + "-" + ((DT_WSTR,2)(((DATEPART("QUARTER",fillDt) – 1) * 3) + 1)) + "-1")))

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail
FacebooktwitterlinkedinrssyoutubeFacebooktwitterlinkedinrssyoutube
Reza Rad on FacebookReza Rad on LinkedinReza Rad on TwitterReza Rad on Youtube
Reza Rad
Trainer, Consultant, Mentor
Reza Rad is a Microsoft Regional Director, an Author, Trainer, Speaker and Consultant. He has a BSc in Computer engineering; he has more than 20 years’ experience in data analysis, BI, databases, programming, and development mostly on Microsoft technologies. He is a Microsoft Data Platform MVP for nine continuous years (from 2011 till now) for his dedication in Microsoft BI. Reza is an active blogger and co-founder of RADACAD. Reza is also co-founder and co-organizer of Difinity conference in New Zealand.
His articles on different aspects of technologies, especially on MS BI, can be found on his blog: https://radacad.com/blog.
He wrote some books on MS SQL BI and also is writing some others, He was also an active member on online technical forums such as MSDN and Experts-Exchange, and was a moderator of MSDN SQL Server forums, and is an MCP, MCSE, and MCITP of BI. He is the leader of the New Zealand Business Intelligence users group. He is also the author of very popular book Power BI from Rookie to Rock Star, which is free with more than 1700 pages of content and the Power BI Pro Architecture published by Apress.
He is an International Speaker in Microsoft Ignite, Microsoft Business Applications Summit, Data Insight Summit, PASS Summit, SQL Saturday and SQL user groups. And He is a Microsoft Certified Trainer.
Reza’s passion is to help you find the best data solution, he is Data enthusiast.

Leave a Reply