="Date Range: "+ UserResponse([Query 1]; "Enter From Date [MM/DD/YYYY]:")+ "To"+ UserResponse([Query 1]; "Enter To Date [MM/DD/YYYY]:")
Above is my code and its working fine to get the user response to the date range prompt…But I need the user entered date in Month - Year(Eg: April - 2009 To May - 2009) date range
Now it is showing as 01/01/2009 To 31/01/2009 format…
I tried with Todate() and FormatDate(), but it throws #Error…
Also within Webi, month and only month needs to be in capital letters if you have it in lower case as you have in your format clause, its treated as minutes. You also shouldn’t have capital YYYY in the format. This too needs to be lower case.
The text in your prompt value is irrelevant and makes no difference to what you enter in the prompt as you can’t enter upper case digits (or at least you can’t in Australia ). The text is merely a note to the user that this is the format that the query is expecting.
So it should be:
“MM/dd/yyyy”
and
“MM/yyyy”
Please also note that if your prompt allows the use of time to also be added your code will still error as it is receiving more than 10 bytes, so you can handle that a couple of ways.
Substring the UserResponse to only select the first 10 char.
Add in a If statement to check the length of the UserResponse. If its more than 10 char, put an addition format string in that handles the time portion of the date.
=FormatDate(ToDate(Substr(UserResponse([Query 1]; "Enter From Date [MM/DD/YYYY]:");1;10);"MM/dd/yyyy");"MM/yyyy")
or as Steve said earlier, break it down, start with one part and build it up
=UserResponse([Query 1]; "Enter From Date [MM/DD/YYYY]:")
then
=Substr(UserResponse([Query 1]; "Enter From Date [MM/DD/YYYY]:");1;10)
then
=ToDate(Substr(UserResponse([Query 1]; "Enter From Date [MM/DD/YYYY]:");1;10);"MM/dd/yyyy")
Finally add the Date Range: description back into it.
="Date Range: "+FormatDate(ToDate(Substr(UserResponse([Query 1]; "Enter From Date [MM/DD/YYYY]:");1;10);"MM/dd/yyyy");"MM/yyyy")
I’ll be surprised if the above doesn’t work though.
You’ll also notice in your code that you have a " before UserResponse and before the 1;5 that shouldn’t be there and also that your substr is 1;5, it needs to be 1;10 for the ToDate.
its working fine till substr().The problem is with Todate() it get parsed but showes #Error in the cell…I am using Teradata(not sure it makes any difference as its at the report level format)
all I am looking is to get Month- year(April - 2009 for example) in the
date range
Thank You
Nikki
=ToDate(Substr(UserResponse([Query 1]; "Enter From Date [MM/DD/YYYY]:");1;10); "MM/yyyy")
=FormatDate(ToDate(Substr(UserResponse([Query 1]; "Enter From Date [MM/DD/YYYY]:");1;10);"MM/dd/yyyy");"MMM yyyy")
And also check that userresponse always returns value like 06/06/2010 12:00:00 otherwise if it’s 6/6/2010 12:00:00, 6/16/2010 12:00:00 then you might need to handle substring function differently,substr([object];1;length([object])-9) from right.