Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSRS Last Week Monday and SUnday

Tags:

I need the last week Monday and Sunday , say today is March 18th hence the SSRS expression should return March 10th -Monday March 16th -Sunday

I was able to get it using SQL

select dateadd(d,(2-datepart(dw, getdate())), dateadd(ww,-1,getdate()))    select dateadd(d,(1-datepart(dw, getdate())), getdate()) 

not sure how to get it done via SSRS expression

like image 522
Alfaromeo Avatar asked Mar 18 '14 06:03

Alfaromeo


People also ask

When is the best time to execute a SSRS report?

Given that the report can be executed at any day and time within the week and it should automatically pick up Monday's and Sunday's date. Any help will be greatly appreciated in giving me a help in writing correct SSRS expression for above If everything seems to be going well, you have obviously overlooked something.

What are the functions of datetime in SSRs?

Date Time Functions of SSRS: Today () - Returns or sets a Date value containing the current date according to your system: Now () - Returns or sets a Date value containing the current date according to your system. MonthName - Returns a String value containing the name of the specified month.

What day of the week does the report automatically pick up?

Given that the report can be executed at any day and time within the week and it should automatically pick up Monday's and Sunday's date. Any help will be greatly appreciated in giving me a help in writing correct SSRS expression for above

How to add/sub abstract date with given date field in SSRs?

To add/substract date or time (day, month, year, sec etc.) with given date field we can use DateADD function in SSRS expression, which returns a Date value containing a date and time value to which a specified time interval has been added: DateDiff - function returns a Long value specifying the number of time intervals between two Date values.


2 Answers

SSRS VBA allows very similar expressions for date manipulation to Sql, the main difference being the use of the DateInterval enum. Without checking your expressions, it will convert to SSRS VBA as follows:

Last Monday:

=DateAdd(DateInterval.Day, 2-WeekDay(Today), DateAdd(DateInterval.Day, -7, Today())) 

Last Sunday:

=DateAdd(DateInterval.Day, 1-WeekDay(Today), Today()) 
like image 169
Chris Latta Avatar answered Sep 20 '22 17:09

Chris Latta


To get Sunday from Last Week : (Note: Last Week Sunday is different from Last Sunday).

=DateAdd(DateInterval.Day, 1-WeekDay(Today), DateAdd(DateInterval.Day, -7, Today)) 

To get Saturday from Last Week :

=DateAdd(DateInterval.Day, 7-WeekDay(Today), DateAdd(DateInterval.Day, -7, Today)) 

with Weekdays values as below:
1 - Sunday
2 - Monday
3 - Tuesday
4 - Wednesday
5 - Thursday
6 - Friday
7 - Saturday

like image 31
Nithya Avatar answered Sep 20 '22 17:09

Nithya