Solved

How do I change SSRS date parameter hours, minutes and seconds?

Posted on 2010-11-26
10
2,051 Views
Last Modified: 2012-05-10
My report has fromdate and todate params.  These are both datetime datatypes and RS provides my users with the little calenders to select their dates.  The problem is with the default setting for hours, minutes and seconds. The fromdate is fine because it defaults to 00:00:00.  But the todate also defaults to 00:00:00 - this causes the report to miss the entire ending day.  How can I change the todate hours, minutes and seconds to 23:59:59.  ?
0
Comment
Question by:Scarlett20
  • 4
  • 3
  • 3
10 Comments
 
LVL 4

Expert Comment

by:joevi
ID: 34219527
Are you using BETWEEN for the Dates in the Dataset Where Clause?
0
 

Author Comment

by:Scarlett20
ID: 34219639
Yes, the stored proc looks like this:

@fromdate datetime,  
@todate datetime
 

and the select statement:
"where T7.servfrom between @fromdate and @todate"
0
 
LVL 10

Expert Comment

by:Mez4343
ID: 34219730
Wouldnt it make sense that the @toDate variable should default to current system date or some date relevant to the data you are running the report for?

DECLARE @fromdate datetime,  
@todate datetime = GetDate();

and the select statement
"where T7.servfrom between @fromdate and @todate"
0
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 

Author Comment

by:Scarlett20
ID: 34219757
This particular report is for previous date ranges, so the todate will never be the current date.

Here's a look at the report header:
Productivity Report for month/s:
4/1/2010 12:00:00 AM thru 7/1/2010 12:00:00 AM

I really wanted data from 4/1/2010 12:00:00 thru 6/30/2010 23:59:59.  Because of the default, I added a day to the todate making it 7/1.
0
 
LVL 10

Expert Comment

by:Mez4343
ID: 34219807
ok you have a relevant date for todate but you need to subtract 1 second. Try DATEADD() function.

DECLARE @fromdate datetime = '7-1-2010 12:00:00 AM'  
DECLARE @todate datetime
SELECT @todate = dateadd(s,-1,@fromdate)
SELECT @todate

http://msdn.microsoft.com/en-us/library/ms186819(SQL.90).aspx
0
 

Author Comment

by:Scarlett20
ID: 34219820
sorry, but I don't want the users to add 1 day to the 'todate' as I did.  so instead of the users entering 7/1/2010, I want them to enter 6/30/2010 - and have the hours, minutes and seconds default to 23:59:59.
0
 
LVL 4

Expert Comment

by:joevi
ID: 34219828
The Evaluation of the between expression will work with the dates converted to text (a string). You'll lose the 'calendars' in the RS list box if you change the datatype to text so you may want to try changing the SP variables to nvarchar datatypes and pass strings (CAST the date parameters as nvarchar) from RS
0
 
LVL 10

Accepted Solution

by:
Mez4343 earned 250 total points
ID: 34219849
Cast the User input date to string and then force the time..

DECLARE @userdate datetime = '6-30-2010 00:00:00 AM'  
DECLARE @todate datetime
SET @todate = CAST(DATEPART(yyyy, @userdate) AS varchar) + '-' +
                     CAST(DATEPART(mm, @userdate) AS varchar) + '-' +
      CAST(DATEPART(dd, @userdate) AS varchar) + ' 23:59:59'
SELECT @todate
0
 
LVL 4

Assisted Solution

by:joevi
joevi earned 250 total points
ID: 34219971
You do NOT need to do all that string concatenation and/or datemath stuff. The dates are already stored as XX/XX/XXXX 00:00:00.

Simply
1) In SQL Server:Change the datatypes for your two SP variables from datetime to nvarchar(10)
2) In Reporting Services: Change the Parameter configurations in your (Stored Procedure) Dataset to:
=FormatDateTime(Parameters!fromdate.Value.ToString)
=FormatDateTime(Parameters!todatedate.Value.ToString)

*assuming your parameters are named fromdate/todate
0
 

Author Closing Comment

by:Scarlett20
ID: 34241691
Hard to know which of you guys/girls had the better solution.  That's because I found my source informix db only had the date (that I queried)  stored as datatype 'date' and not 'datetime'.   It loaded into our sql warehouse as datetime, but of course the times defaulted to all zeroes.   thanks to both of you - I really appreciate your help.
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to Parameterize an update sql using a Pivot sql 7 51
Query 14 57
Find data in a column which is not in  a date format 29 35
SSRS Dynamic Column Names - Last 8 Weeks 3 43
Hi, I am very much excited today since I'm going to share something very exciting Tool used for Analytical Reporting and that's nothing but MICROSTRATEGY. Actually there are lot of other tools available in the market for Reporting Such as Co…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question