reporting-servicesexpressionrdl

SSRS - Remove seconds from Time field


How do I remove seconds from Time field? I tried:

=Rset(Fields!hr_saida.Value,5) = return #Error
=TimeValue(Fields!hr_saida.Value) = return #Error
=FormatDateTime(CDate(Fields!hr_saida.Value),"hh:mm") = return #Error

I also tried set my text box property to Number > 13:30, but still shows "hh:mm:ss" How do I remove? Thank you.


Solution

  • Another option in addition to the one from @Yuriy is:

    =Format(Fields!hr_saida.Value, "HH:mm")
    

    for 24 Hour time

    or:

    =Format(Fields!hr_saida.Value, "hh:mm")
    

    for AM/PM.

    If your field isn't DateTime you may need to use CDate() as well.

    Edit after comment

    Try:

    =Left(Fields!hr_saida.Value.ToString(), 5)
    

    RSet also works with ToString.

    That works for 24 hour time - you could use something like:

    =CDate(Fields!hr_saida.Value.ToString()).ToString("hh:mm")
    

    for AM/PM.

    In my testing I was getting similar errors like:

    Unable to cast object of type 'System.TimeSpan' to type 'System.IConvertible'.
    

    and

    Conversion from type 'TimeSpan' to type 'Date' is not valid.

    I guess the conclusion here is that SSRS really dislikes the SQL Server time datatype.