How to add time (data type) as parameter - reporting-services

I need to create a report that allows the user to give a date and time range for a report. I can set up the StartDate and EndDate (DateTime data type), but I can't seem to figure out how to add StartTime and EndTime.
This is a report where they want to view what was processed between a certain date and time. Is there anything that I can do so that the user can choose/enter a value for time in a report?

As #WillA mentioned in a comment, there is no date + time picker in SSRS. However, the datepicker that comes with a DateTime parameter does allow manually entering a time component.
First, here's what happens if you select just a date in the picker:
If you render this in a TextBox with format string HH:mm:ss, MMM d `yy, this will become:
00:00:00, Dec 9 `12
However, if the user manually :'( enters a time component it will work, e.g.
This will be rendered (with the same format) as such:
15:27:00, Dec 9 `12
This is not a very user-friendly solution though.

Related

How can I change the date format of a date/time SSRS parameter - this is specific to en-SC culture?

I have an SSRS report that has a start and end date parameter (set to the date/time type) so that the user can choose the date range. The report sets the Localization Language value based on a parameter that is passed in at run time.
This works great for en-GB but we have a customer in the Seychelles and when the localization is set to en-SC, the date format of the 2 parameters defaults to mm-dd-yyyy, but this is incorrect as the date format should be dd-mm-yyyy. Because of this, the user is unable to set the dates correctly as choosing the 31st January for example gives a 'The value provided for the report parameter 'startdate' is not valid for its type' error.
When I drop down the date picker and pick 31st January, it fills the date in as 31/01/2023 but then displays the error. I have my Windows Region set to "Seychelles" and Regional Format to "English (Seychelles)".
Is there anything I can change to get this to work or is it a bug in SSRS?

Change the value of a date field

Is there a way to take a field(DateRequired for example) and adjust the date being displayed to show differently from the actual date? For example, if the date in DateRequired is 7/20/17, I would like it to display 7/13/17, a week before the actual date.
Yeah, SSRS utilizes VB as a language for custom expressions and code that you create in the report. If you right-click on the object that your date is in (textbox/table cell etc...) and go to the "Expression" wizard, you will be able to modify your date field.
To add or remove a specific amount of time to a date, utilize the DateAdd function.
=DateAdd(DateInterval.Day, -7, CDate(Fields!YourDateColumn.Value))

How to separate time from datetimepicker vb.net

I have one datetimepicker which custom format MM/dd/yyyy h:mm tt
I have database and has a column "Date_Time" the value of the DateTimePicker is saved to the column Date_Time formatted like this MM/dd/yyyy h:mm tt
now i want to get the Time only not the entire value of datetimepicker just the hh:mm tt from the column Date_Time
SORRY FOR MY GRAMMAR
How about DateTime.TimeOfDay?
It returns the time that has elapsed since midnight (which is what h:mm tt stands for in your code).
Dim Time As TimeSpan = DateTimePicker1.Value.TimeOfDay 'Would return for example 3:14 PM
The answer above is right.
If you need to get time string, you can use also another way, which includes a formating:
Dim myTimeString = DateTimePicker1.value.ToString("hh:mm")
You can do that for any part of the DateTime value.
You are heading for a new problem. If you zero out the Date portion and store the result to a DateTime column, you will end up storing something like: 0001-01-01 16:43:12. A column defined as DateTime will always have a Date, as will a DateTime variable.
The first problem may be getting MySQL to accept a non-Date in a DateTime column. Using a column defined as DateTime(3), mine throws a generic fatal error exception trying to store just a TimeSpan to it:
cmd.Parameters.Add("#p3", MySqlDbType.DateTime).Value = DateTime.Now.TimeOfDay
cmd.ExecuteNonQuery()
If MySqlDbType.Time is used as the type, I get an exception that the time is an invalid value for the column...and it is.
If you manage to store it somehow, the next problem will be when/if you want to put that value back in a DateTimePicker: the minimum date you can enter is 1/1/1753 (first full year of the current calendar). So your DateTime var with the Date zeroed out wont work. You'll first have to restore the date portion, but the Date, Year etc are all readonly.
Solution 1
Define the column as Time(0) which will store hours, minutes and seconds. Use the value in the parens to specify fractional seconds, for instance Time(3) will also store milliseconds. When you read the data, store it to a TimeSpan.
Then in your UI use a different control, otherwise you have the same problem - adding some Date data to it to make it usable in a DateTimePicker
Solution 2
Use a DateTimePicker and a DateTime column, but just ignore the Date portion in your code. This will allow you to use what is in the Database as is with the control.
You can get the time selected with DateTime.TimeOfDay but storing and reusing it may be problematic.

Converting user-typed dates from date picker

I have a report that uses date params (so have to be datetime in SSRS, which sucks to start with). When the user enters a date such as "5/1" it creates a DateTimeOffset data type and I can't find anyway to cast it to anything else, format it, or concatenate in a text box. I tried casting to a date to a string, etc. All I get is:
Conversion from type 'DateTimeOffset' to type 'String' is not valid. ('String' is replaced by anything I try to cast it to)
Surely there must be a way to have a text box show "From 5/1/2013 to 5/31/2013" when the user types "5/1" and "5/31" in the date field? Does Microsoft really think computer-literate people want to pick up the mouse to use their date picker instead of using tab?
Try the following expression:
="From " & Format(Parameters!Param1.Value.DateTime, "M/d/yyyy") & " to ..... etc"
To test this expression I've created a fresh report, added a DateTime parameter, and entered "5/1" in the textbox, hit enter. The report comes up with the following textbox:
From 1/5/2013 to ..... etc
For my locale, this is correct, because when entering DateTime values days are assumed to come before months. When the report is viewed the textbox will also update and show:
5-1-2013 0:00:00 +01:00
From this you should be able to extrapolate and use it for a second parameter as well, extending the expression to show the exact string you need in your report.
The Parameters!Param1.Value.DateTime helped when the user omits the year, but it broke down when the user decides to include the year. I couldn't get it to work under both conditions.
Try this.
Include the date parameter value as a field in your resultset. Your SQL might look like:
SELECT field1, field2, Convert(date, #FromDate) [FromDate_param] FROM table
Then you can create an expression in SSRS like:
="From " & Format(First(Fields!FromDate_param.Value), "M/d/yy")

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