So I have an enddate parameter in my report and I have the following code under Default Value to get me the last day of the previous month.
=DateAdd("d", -1, DateSerial(Year(Now()), Month(Now()), 1))
This works fine, returning 04-30-2016. That's fine and dandy but when I go to use the Subscription piece in SSRS it has the datetime field as: 04-30-2016 12:00:00 AM. So I tried doing the following to my code to have it shave off three milliseconds:
=DateAdd("ms", -3,DateAdd("d", 0, DateSerial(Year(Now()), Month(Now()), 1)))
When I try to run my report I get the following error:
The DefaultValue expression for the report parameter "enddate" contains an error: Argument 'Interval' is not a valid value. (rsRuntimeErrorInExpression)
How do I fix this error and get my report running as it should?
The AddMilliseconds function will work for you in this case.
=DateAdd("d",-1,DateSerial(Now.Year,Now.Month, 1)).AddMilliseconds(-3)
This gives you the last day of the previous month substracting three milliseconds.
Let me know if this helps.
Related
From my internet page/portal I generate my report:
http://localhost/BOPortal/Reports/View/Events?FromDate=2016-06-22%2022:00:00&ToDate=2016-06-23%2021:59:00&Language=en-GB&User=admin
When it is run the ToDate parameter is wrong. It gives me the date from the URL plus one day 24/06/2016 21:58:59.
Why?
I am trying to set a default parameter value in SSRS report. I want to test the current date to see if it equals the first day of the week (in my case Monday). If it is the first day of week, then I want the default value to be current date minus 2 days, if it is not the first day of the week then I want the default value to be current date minus 1 day.
I seem to have a syntax problem but it doesn't tell me where. My parameters are StartDate and EndDate.
this is what I've tried:
=iif(weekday(Today(),FirstDayOfWeek.Monday)==1,DateAdd("d",-2,today(),DateAdd("d",-1,today())
this is the generic error I get:
The value expression for the report parameter 'StartDate' contains eror:[BC30201] Expression expected.
Where am I going wrong?
You are trying to use Sql syntax in a SSRS VBA expression. SSRS VBA allows very similar expressions for date manipulation to Sql, the main difference being the use of the DateInterval enum.
So your expression needs to use VBA syntax:
=IIF(Weekday(Today, FirstDayOfWeek.Monday) = 1, DateAdd(DateInterval.Day, -2, Today), DateAdd(DateInterval.Day, , -1, Today))
It appears that you are missing a closing parentheses after the first logical part of the if statement and another to close the statement.
=iif(weekday(Today(),FirstDayOfWeek.Monday)==1,DateAdd("d",-2,today()),DateAdd("d",-1,today()))
any advice appreciated
I have as a column heading the expression =WeekdayName(weekday(fields!date.value))
This returns the day of the week, however, it is returning a day of the week one day in advance, eg when I put Monday's dates in the parameter it shows as 'Tuesday' in the report.
My question is can the above expression be tweaked to show the WeekdayName one day before, eg =WeekdayName(weekday(fields!date.value -1)) ? I tried this but got an error.
Thanks.
So you want to subtract one day from the your incoming date then you can use the
= DateAdd("d", -1, yourdateField)
This way you can subtract the any number of days from your date.
But did you try to see why it is giving the day of previous date. Do check the system date time or else check with the
=WeekdayName(weekday(Today()))
and see if it gives you the correct day of week for current date.
Weekday and weekdayname functions have both another optional argument for defining the starting day of the week.
Problem is the 2 functions don' t default this argument to the same value so depending on your server settings you should explicitly set the second argument of these functions.
No need to invoke a date function. As the weekday() function returns and integer you can offset the result and use the Mod operator to keep it in bounds:
=WeekdayName((weekday(fields!date.value)+5) Mod 7)+1)
The parenthesis are important to ensure the addition comes first.
Just for reference:
OP asked again because of the weekday offset and this is the correct provided solution.
=WeekdayName(weekday(Today())) gives me tomorrow
=WeekdayName(Weekday(Today(),FirstDayOfWeek.System))
I have a form in access when has two textboxes.
The first called txtDateBox which allows the user to select a date.
The second which is called DayBox which displays the days name.
I have a control source in DayBox to get the name of the day.
=WeekdayName(Weekday([txtDateBox])-1)
This works fine until I select a sunday date.
It will then display a #Func! message in the textbox and will not allow me to compile my automatic reports.
The problem is because WeekdayName(0) triggers error #5, "Invalid procedure call or argument."
Avoid the error by using DateAdd to subtract one day from txtDateBox before you give it to Weekday. Here is an Immediate window session to show you what I mean:
txtDateBox = #2014-1-5#
? Format(txtDateBox, "ddd, mmm d, yyyy")
Sun, Jan 5, 2014
? DateAdd("d", -1, txtDateBox)
1/4/2014
? Weekday(DateAdd("d", -1, txtDateBox))
7
? WeekdayName(Weekday(DateAdd("d", -1, txtDateBox)))
Saturday
the following error is displayed when deploy reports,
"The Value expression for the report parameter ‘Year’ contains an error: [BC30201] Expression expected "
The problem is in default value expression for parameter Year.
=Switch(
CInt(System.DateTime.Now.Month) >3,
Year(Today()),
CInt(System.DateTime.Now.Month) <=3,
{Year(Today.AddYears(-1)),Year(Today())}
)
Any idea?
I'm pretty sure you can just rewrite the above as:
=IIf(Month(Today) > 3, Year(Today), Year(DateAdd(DateInterval.Year, -1, Today)))
i.e. If Today is in April to December, use the current year, else use the previous year.