0
votes

I have build an SSRS report. I set a default date parameters as following: startdate : take the first day of the month. EndDate : take yesterday date.

This code for the beginning of the month =DateSerial(Year(Now()), Month(Now()), "1").AddMonths(0) This code for yesterdate date

=DateAdd(DateInterval.Day,-1,CDate(FormatDateTime(Now,DateFormat.ShortDate)))

The date works perfectly until, a new month comes, the result will be like this: startdate: 01. 5 2019 end date: 30. 4 2019

where it should be : startdate: 01. 4 2019 end date: 30. 4 2019

how can i make sure if a new date comes , it will take the first day of the previous month.

2

2 Answers

0
votes

You should add an IIF statement to check if today is the first day of the month. The following expression should do what you need.

=IIF(DatePart(DateInterval.Day, Today()) = 1, 
     DateSerial(Year(Now()), Month(Now())-1, 1), 
     DateSerial(Year(Now()), Month(Now()), 1))
-1
votes

Just change your StartDate to reference yesterday's date:

=DateSerial(Year(Today.AddDays(-1)),Month(Today.AddDays(-1)),1)