SSRS expression fails for IIF date with #error - date

A stored procedure is included in a report builder file of type rdl. the stored procedure has many fields. One of the fields returns a date (not datetime). The desired outcome in the report is to show the date only and empty field if no date is returned.
With just the field value the result shows empty field when the date is null otherwise shows the date with a datetime value.
Using IIF to check the value for 'nothing' as shown below.
=IIF(Fields!myDate.Value Is Nothing,"",Fields!myDate.Value)
The output is the same. A datetime value is shown when date is available.
Attempting to use the shortDateString() function yields the correct result in when a date is present but #Error when a date is NOT present. This is the statement:
=IIF(Fields!rlsPromoDate.Value Is Nothing, "",
Fields!rlsPromoDate.Value.ToShortDateString())
The version below was attempted. No errors resulted however the date was not returned but this was "Microsoft.ReportingServices.ReportProcessing.OnDemandReportObjectModel.FieldImpl".
=IIF(Fields!myDate.Value Is Nothing,"", String.Format("{0:MM/dd/yyyy}",
Fields!myDate))
Please advise if there is a solution.

Try the following:
=IIF(Fields!rlsPromoDate.Value Is Nothing, "", Format(Fields!rlsPromoDate.Value, "dd/MM/yyyy"))
or whatever date format you'd actually like to use.

Related

Reading weird date format in hive

I have a column which contians date as string but in many formats like - dd/MM/yy, dd/MMM/yyy .. etc etc. And I am using the following code to convert all strings to one specific date format (yyyy-MM-dd) in hive :
select
from_unixtime(unix_timestamp('31/02/2021','dd/MM/yyyy'),'yyyy-MM-dd')
but this gives me 2021-03-03 in HIVE.
Is there any other way to identify such invalid dates and give null.
Assume, you recognized format correctly and it is exactly 'dd/MM/yyyy' and date is invalid one '31/02/2021'.
unix_timestamp function in such case will move date to the next month and there is no way to change it's behavior. But you can check if the date double-converted from original string to timestamp and back to original format is the same. In case it is not the same, then the date is invalid one.
case
-- check double-converted date is the same as original string
when from_unixtime(unix_timestamp(date_col,'dd/MM/yyyy'),'dd/MM/yyyy') = date_col
--convert to yyyy-MM-dd if the date is valid
then from_unixtime(unix_timestamp('31/02/2021','dd/MM/yyyy'),'yyyy-MM-dd')
else null -- null if invalid date
end as date_converted

Crystal Reports Date Parameter format

I have a date parameter in my report, which pulls data based on a date in the report which is formatted mm/dd/yyyy. However when the parameter prompts for an input, the parameter requests the date in yyyy-mm-dd.
When entered, data is still correctly shown, however for the user I'd prefer the parameter to be shown mm/dd/yyyy.
How do I change how the parameter date formatting?
All date Parameter from your Crystal Report must set as string format.
Do not rely on date itself
for example you have a date in your query something like:
20190322 your parameter must looks like this so that it will match when passing it.

Date format in SSRS Expression

I am trying to change the date format for one of my field to dd/MM/yyyy but every time I used the below expression I get dd/MM/yyyy as the value in the cell instead of changing the format.
The data source that I am using is Teradata.
Expression used: =Format(FormatDateTime(Fields!DATE.Value, DateFormat.ShortDate),"dd/MM/yyyy")
Can some one help me with where am I going wrong.
Any help would be appreciated.
The FormatDateTime function returns a string instead of a date. When the FORMAT function tries to format it, it doesn't find a date field so it returns the characters in the format.
If your field is a date, you should be able to format the field without conversion:
=Format(Fields!DATE.Value,"dd/MM/yyyy")
If it does need to be converted first, try using the CDATE function:
=Format(CDATE(Fields!DATE.Value),"dd/MM/yyyy")

How to add 13min's time in Time Field(not date time field) Crystal reports

I tried using Dateadd('n',13,{fieldname}).
but it throws an error not a valid date time field cause it is time field.
is there any way to convert it to datetime and add the value and revert it into time field?
Thanks.
Try this formula:
DateAdd('n',13,DateTime(CurrentDate, {fieldname}))
The DateTime(date, time) function will create a DateTime value that works in the DateAdd() function. This will only work if the {fieldname} is a Time data type though.
If {fieldname} is a string, you will need to convert it to a Time data type first using the Time(time) function.
The formula I suggested above will append your time value to today's date. You will then need to format the DateTime value it returns to only display the time value. This can be done by right clicking the field in your crystal report and clicking Format Field and setting the Style on the Date and Time tab.

Why does DateDiff function fail with "Invalid operation: Data value "0" has invalid format"in Redshift

I have a datediff() function that throws an exception.
I am trying to calculate the number of days between two dates. The rub is that one date is a converted integer value in YYYYMMDD format and the second date field is a timestamp. So, in the snippet below I am doing what I think are the correct conversions. Sometimes, it runs actually.
The message I get is: Amazon Invalid operation: Data value "0" has invalid format.
select site, datediff(days,to_date(cast(posting_dt_sk as varchar), 'YYYYMMDD'),trunc(ship_dt)) days_to_ship from sales_table
Later I added a Where-clause as to ignore empty values thinking I had bad data but that's not it. I still get the message.
where posting_dt_sk is not null and posting_dt_sk > 0
It all looks right to me, but it fails.