In my report I am filtering results depending on a date range, I have the default language of my report set to English (United Kingdom), however my parameters fail to recognise a date such as 13/01/2005 and displays an error message, however if I change the date to 01/13/2005 it filters the results correctly.
The actual date which appears in my results is formatted correctly.
Is there anything I can do to rectify the format in the parameter value?I suppose you have a English US setting on you database.
I also suppose reinstalling the databaseserver would not be an option
I'd say you convert the dates in between your application and the database and pass the dates as strings to your database (MM/DD/YYYY) but what usually works as well and always is interpreted correctly is YYYY-MM-DD (HH:MM:SS).
In that output setting the days and the months never get mixed (not that i know of anyway).
I haven't found a way in SQL Server to change that setting, but if you do, just let me know, i certainly could mage good use of it
btw change the setting without reinstalling it off course.|||This may or may not help!
But here is a Standard Date Formatter UDF that accepts dates in a lot of different formats and returns a value.
If necessary I think you could modify to ensure that whatever date format the User enters you can call the UDF and get a standard date formate back to use within your SQL to ensure you get the ranges for the date (in almost whatever format) they entered the date in via the parameter.
CREATE FUNCTION dbo.fn_FormatDateTime
(
@.dt DATETIME,
@.format VARCHAR(16)
)
RETURNS VARCHAR(64)
AS
BEGIN
DECLARE @.dtVC VARCHAR(64)
SELECT @.dtVC = CASE @.format
WHEN 'LONGDATE' THEN
DATENAME(dw, @.dt)
+ ',' + SPACE(1) + DATENAME(m, @.dt)
+ SPACE(1) + CAST(DAY(@.dt) AS VARCHAR(2))
+ ',' + SPACE(1) + CAST(YEAR(@.dt) AS CHAR(4))
WHEN 'LONGDATEANDTIME' THEN
DATENAME(dw, @.dt)
+ ',' + SPACE(1) + DATENAME(m, @.dt)
+ SPACE(1) + CAST(DAY(@.dt) AS VARCHAR(2))
+ ',' + SPACE(1) + CAST(YEAR(@.dt) AS CHAR(4))
+ SPACE(1) + RIGHT(CONVERT(CHAR(20),
@.dt - CONVERT(DATETIME, CONVERT(CHAR(8),
@.dt, 112)), 22), 11)
WHEN 'SHORTDATE' THEN
LEFT(CONVERT(CHAR(19), @.dt, 0), 11)
WHEN 'SHORTDATEANDTIME' THEN
REPLACE(REPLACE(CONVERT(CHAR(19), @.dt, 0),
'AM', ' AM'), 'PM', ' PM')
WHEN 'UNIXTIMESTAMP' THEN
CAST(DATEDIFF(SECOND, '19700101', @.dt)
AS VARCHAR(64))
WHEN 'YYYYMMDD' THEN
CONVERT(CHAR(8), @.dt, 112)
WHEN 'YYYY-MM-DD' THEN
CONVERT(CHAR(10), @.dt, 23)
WHEN 'YYMMDD' THEN
CONVERT(VARCHAR(8), @.dt, 12)
WHEN 'YY-MM-DD' THEN
STUFF(STUFF(CONVERT(VARCHAR(8), @.dt, 12),
5, 0, '-'), 3, 0, '-')
WHEN 'MMDDYY' THEN
REPLACE(CONVERT(CHAR(8), @.dt, 10), '-', SPACE(0))
WHEN 'MM-DD-YY' THEN
CONVERT(CHAR(8), @.dt, 10)
WHEN 'MM/DD/YY' THEN
CONVERT(CHAR(8), @.dt, 1)
WHEN 'MM/DD/YYYY' THEN
CONVERT(CHAR(10), @.dt, 101)
WHEN 'DDMMYY' THEN
REPLACE(CONVERT(CHAR(8), @.dt, 3), '/', SPACE(0))
WHEN 'DD-MM-YY' THEN
REPLACE(CONVERT(CHAR(8), @.dt, 3), '/', '-')
WHEN 'DD/MM/YY' THEN
CONVERT(CHAR(8), @.dt, 3)
WHEN 'DD/MM/YYYY' THEN
CONVERT(CHAR(10), @.dt, 103)
WHEN 'HH:MM:SS 24' THEN
CONVERT(CHAR(8), @.dt, 8)
WHEN 'HH:MM 24' THEN
LEFT(CONVERT(VARCHAR(8), @.dt, 8), 5)
WHEN 'HH:MM:SS 12' THEN
LTRIM(RIGHT(CONVERT(VARCHAR(20), @.dt, 22), 11))
WHEN 'HH:MM 12' THEN
LTRIM(SUBSTRING(CONVERT(
VARCHAR(20), @.dt, 22), 10, 5)
+ RIGHT(CONVERT(VARCHAR(20), @.dt, 22), 3))
ELSE
'Invalid format specified'
END
RETURN @.dtVC
END
Maybe this is a starting point that you can work with!
Best Regards,
Joe|||Sorry - but sometimes I thake things for granted!!
When I define a parameter within Reporting Services and the parameter is a date - I just define define the date parameter as a string - then pass the parameter to my SQL (a stored procedure) and then go from there.
So the UDF that I gave you would allow you to define a value and on the fly convert so you then can compare the passed date parameter in the format you want (reformatted against the UDF) against the dates within your table.
One other thing, I think that within your SP - you take the date that was given as a parameter, convert to the format you want and use ISDATE to determine if the parameter is a valid date and if not have a "variable" field that always gets passed back to RS - (just like within SQL and you want to do a global count - EXPR) and if the date is invalid pop a value within the variable field as invalid date or whatever - if not carry on!
I have the same problem (kind of) here in Bangkok in that their yearly calendar is 543 years ahead of a Western calendar so for todays date 7/22/2005 in comes in as a parameter as 7/22/2548 or 22/7/2548 so I always have to inspect what format MM/DD/YYYY or DD/MM/YYYY and then inspect the YYYY to determine if in Thai years then subtract 543 or leave alone.
Hope I have been clear enough!
Best Regards,
Joe
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment