Report Builder - Set datetime parameter - reporting-services

I have a report that has parameters StartDate and EndDate. I would like the EndDate parameter's time part to default to the end of the day when selected from the drop down.
For instance, if a user selects 5/15/2008 from the dropdown, the value shown in the box should be '5/15/2008 23:59:59' not '5/15/2008 12:00:00'
Its pretty easy to do this in .Net using the event model and a line of code but in Report Builder 2.0, what would I need to do?
Is there code that I need to write for this or did I miss some funky expression that could handle this?
Thanks.
AboutDev

I would suggest setting the default parameter in the Report Parameters section. You can get to this from Report > Report Parameters.
This allows you to set a non-queried default. There you can enter an expression like
=DateAdd(Microsoft.VisualBasic.DateInterval.Second ,-1,dateadd("d",1,Today))
That should give you a default for the end of today.
Edit: Really only useful for a single default value.

It's been awhile since I've used SSRS, so bear with me. You'll have to do a little translation, but here's what I've done in the past.
When you define your EndDate parameter, create an additional parameter named EndDateEOD, after EndDate in your list of parameters. Make this parameter a hidden value, and set it to the last moment of the day, similar to the way that Jeremy calculates it.
Then you can use #EndDateEOD in your report query where you have #EndDate now.
When StartDate is selected, you could have EndDate default to its value, so that EndDateEOD will automatically be set to the end of the start date.

Use the parameter in a DATEADD() expression in your dataset.
Rather than
...WHERE end_date = #end_date
do something like this:
...WHERE end_date = DATEADD(ms, -3, #end_date + 1)
That will go forward a day (the +1), then go back 3 milliseconds, to the last instant of the day recordable by a datetime.

You can do something like this:
=CDate(Parameters!StartDate.Value + " 23:59:59")
The part of Parameters!StartDate.Value can be any date but not the EndDate.Value itself. Eg:
- Today()
- Last day of the month from start date:
=CDate(DateSerial(Year(Parameters!StartDate.Value), Month(Parameters!StartDate.Value) + 1, 0)+" 23:59:59")
Hope this help.

Related

Start Date Range parameters in SSRS

When I set up my SSRS report originally I set it up to look at the current day so my where clause in my query was:
Where
trunc(START_DAY) >= current_date -1 And
trunc(START_DAY) <= current_date
Now I want to add parameters to select just the "START_DAY."
How would I go about setting this up?
It sounds like you're using Oracle where the TRUNC function is converting your datetime to a date.
In this case you would set up a date parameter in SSRS. You can add a default date of today or yesterday.
Then, in the SSRS dataset, add the parameter to your Oracle query.
Where TRUNC(START_DAY) = :DATE_PARAM
You may need to map the parameter manually in the Parameters tab of the dataset.

Set Default parameter in SSRS from a dataset

How can i set the default parameter in SSRS using a value from Dataset?
I want the default parameter to be the previous month date that is selected from a table tblPeriod(per_id, lastDay)
tblPeriod stores the months in a set of 20 year with last day storing the last day in a month.
e.g
2000, 31-Dec-2016
1999, 30-Nov-2016
I wrote this SP getPeriod which works like this-
select per_id, lastDay , (select per_id from tblPeriod where lastDay < getDate()) as maxDate from tblPeriod
The report populates a drop down with all period values
How to make the default date as previous month end date using the maxDate value returned by the Stored Procedure?
<ReportParameter Name="period">
<DataType>Integer</DataType>
<Prompt>Period</Prompt>
<ValidValues>
<DataSetReference>
<DataSetName>Periods</DataSetName>
<ValueField>per_id</ValueField>
<LabelField>lastDay</LabelField>
</DataSetReference>
</ValidValues>
</ReportParameter>
I would also like to know how to set the top most item in a parameter drop down as the default selected item in the report
Click on default value option then click on function then you can write a function to get the date you are wanting like [#parameterName] will get the entered parameter then use some of the math function to modify it like you need. Your problem is hard to solve without seeing what you are doing in the GUI and you will have to get pretty creative to solve it.
Sorry I can't be of more help. If you add some screen shots I may be able to help more.

Comparing todays date against first day of the week

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()))

sql query to get a scheduled report to run for that curent month only

I have an SSRS 2005 report that has a dataset for to an Oracle database. The report that i have essentially just pulls all data back from an audit log. This report works perfectly fine and i have scheduled thi to run and send an email using the new subscription method within SSRS.
The only issue i have is i want the report to run on the last day of the month (its set up to do this alreday) and run the report based on that month only. Getting the report to run specifically for a month is what im unsure on? I though i would be able to set parameters within the report but these only enable my user to select a calendar date?
Is there a DATEADD or DATEPART type of function i can use to complete this task?
Regards
B
Best bet would be to set up a dynamic date default for the date patameter at the report level, and set up the subscription to use this default value, so whenever the subscription runs it would automatically have the appropriate date.
Probably the easiest thing to do is set the parameter as the current date, if that would work, e.g. something like =Today(). So that will be calculated whenever the subscription runs.
You can set the default value for whatever you need; first day of the current month, etc. You should able to set whatever value you need without too much trouble.
So for the first day of the month something like:
=DateSerial(Year(Today()), Month(Today()), 1).
Users running the report ad-hoc could just reset the parameter as required.
I'm assuming the report handles the amount of data to return correctly assuming the right data parameter is sent.
2 Parameters #DateFrom and #DateTo
Default Value for #DateFrom that outputs the first day of the current month:
=DateAdd("d",-Day(Today())+1,Today())
Default Value for #DateTo that outputs the last day of the current month:
=DateAdd("d",-Day(Today())+1,DateAdd("m",1,Today()))

Reporting Services Remove Time from DateTime in Expression

I'm trying to populate an expression (default value of a parameter) with an explicit time. How do I remove the time from the the "now" function?
Something like this:
=FormatDateTime(Now, DateFormat.ShortDate)
Where "Now" can be replaced by the name of the date/time field that you're trying to convert.)
For instance,
=FormatDateTime(Fields!StartDate.Value, DateFormat.ShortDate)
Since SSRS utilizes VB, you can do the following:
=Today() 'returns date only
If you were to use:
=Now() 'returns date and current timestamp
=CDate(Now).ToString("dd/MM/yyyy")
Although you are hardcoding the date formart to a locale.
If you have to display the field on report header then try this...
RightClick on Textbox > Properties > Category > date > select *Format (Note this will maintain the regional settings).
Since this question has been viewed many times, I'm posting it... Hope it helps.
Just use DateValue(Now) if you want the result to be of DateTime data type.
If expected data format is MM-dd-yyyy then try below,
=CDate(Now).ToString("MM-dd-yyyy")
Similarly you can try this one,
=Format(Today(),"MM-dd-yyyy")
Output: 02-04-2016
Note:
Now() will show you current date and time stamp
Today() will show you Date only not time part.
Also you can set any date format instead of MM-dd-yyyy in my example.
In the format property of any textbox field you can use format strings:
e.g. D/M/Y, D, etc.
One thing that might help others is that you can place: =CDate(Now).ToString("dd/MM/yyyy") in the Format String Property of SSRS which can be obtained by right clicking the column. That is the cleanest way to do it. Then your expression won't be too large and difficult to visually "parse" :)
FormatDateTime(Parameter.StartDate.Value)
I'm coming late in the game but I tried all of the solutions above! couldn't get it to drop the zero's in the parameter and give me a default (it ignored the formatting or appeared blank). I was using SSRS 2005 so was struggling with its clunky / buggy issues.
My workaround was to add a column to the custom [DimDate] table in my database that I was pulling dates from. I added a column that was a string representation in the desired format of the [date] column. I then created 2 new Datasets in SSRS that pulled in the following queries for 2 defaults for my 'To' & 'From' date defaults -
'from'
SELECT Datestring
FROM dbo.dimDate
WHERE [date] = ( SELECT MAX(date)
FROM dbo.dimdate
WHERE date < DATEADD(month, -3, GETDATE()
)
'to'
SELECT Datestring
FROM dbo.dimDate
WHERE [date] = ( SELECT MAX(date)
FROM dbo.dimdate
WHERE date <= GETDATE()
)
My solution for a Date/Time parameter:
=CDate(Today())
The trick is to convert back to a DateTime as recommend Perhentian.
Found the solution from here
This gets the last second of the previous day:
DateAdd("s",-1,DateAdd("d",1,Today())
This returns the last second of the previous week:
=dateadd("d", -Weekday(Now), (DateAdd("s",-1,DateAdd("d",1,Today()))))
This should be done in the dataset. You could do this
Select CAST(CAST(YourDateTime as date) AS Varchar(11)) as DateColumnName
In SSRS Layout, just do this =Fields!DateColumnName.Value
Just concatenate a string to the end of the value:
Fields!<your field>.Value & " " 'test'
and this should work!