Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In SSIS, how do I get the date for a specific day of the week? For example, how do I get last Sunday's date?

I assume I have to do some subtraction on the day-of-week, but not sure:

share|improve this question

You can use the following code to get the date for any given day in the current week:

DECLARE @DesiredDay INT = 0;
SET DATEFIRST 1; /* Monday is day 1 */
SET @OutputDate = DATEADD(d, @DesiredDay - DATEPART(DW, GETDATE()), GETDATE());
SELECT @OutputDate;

I'm setting @DesiredDay to 0 since you requested Sunday in your question. For Monday, set this to 1, for Tuesday set it to 2, etc.

share|improve this answer
I'm after the SSIS expression please Max. – PeterX Feb 10 '14 at 0:34
In SSIS, you could obtain the date for Sunday using : DATEADD("d", 0 - DATEPART("dw", GETDATE()), GETDATE()) – Max Vernon Feb 10 '14 at 4:49
Yes, that's what I was thinking - adjust the "0" value the day-of-the-week you require. – PeterX Feb 11 '14 at 6:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.