[Question | Telerik Standalone Report Designer]: How to format date as HH:MM:SS without getting an error?

1 Answer 155 Views
Conditional Formatting DataSource SQL Expressions General Discussions Report Designer (standalone) Report Parameters Sorting
Austin
Top achievements
Rank 2
Iron
Iron
Iron
Austin asked on 04 Apr 2023, 08:06 PM

Good Afternoon Telerik Support,

 

I am trying to format an Averaged date & time between two values as HH:MM:SS (see screenshot). However, when I used the format Date & Time value for HH:MM:SS it gives me the following error (see screenshot) How can I fix this as I do not want the milliseconds at the end and it seems to keep adding it.

 

(Average Combined Time)

 

(Error After formatting it to HH:MM:SS ({0:hh:mm:ss})

 

 

Thank you!

1 Answer, 1 is accepted

Sort by
1
Accepted
Dimitar
Telerik team
answered on 07 Apr 2023, 10:19 AM

Hi Austin,

To achieve this, you may call the DateTime.ToString Method method on your date with the "hh:mm:ss" string as the argument, for example:

= Now().ToString("hh:mm:ss")

Please test this approach and let me know if that helps.

Regards,
Dimitar
Progress Telerik

Brand new Telerik Reporting course in Virtual Classroom - the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products. Check it out at https://learn.telerik.com/.
Austin
Top achievements
Rank 2
Iron
Iron
Iron
commented on 15 May 2023, 06:31 PM

That worked perfectly, Thank you!!!
Austin
Top achievements
Rank 2
Iron
Iron
Iron
commented on 28 Jul 2023, 04:27 PM

Hi Dimitar,

Something happened with the same report and now its not working and back to the same way before. I am unsure where to put the code now for the averages to be in HH:MM:SS since they are still displaying as 01:15:12.941841

Thank you!!

Dimitar
Telerik team
commented on 02 Aug 2023, 08:28 AM

Hi Austin,

I am sorry to hear that you are experiencing problems with the formatting again. Would you please show me your expression? My suspicion is that the ToString("hh:mm:ss") is not called in the correct place. Please make sure that you are calling it on the field representing the average time or on the resulting datetime object if you are subtracting the dates.

If you would need further assistance, it would be best to attach a sample report with this problem reproduced so that I may investigate it locally. I will be looking forward to an update from you.

Austin
Top achievements
Rank 2
Iron
Iron
Iron
commented on 11 Aug 2023, 04:02 AM

Hi Dimitar,

 

I think I may be placing it in the wrong place? See my screenshot below

 

Dimitar
Telerik team
commented on 14 Aug 2023, 11:33 AM

Hi Austin,

Thank you for the screenshot!

The screenshot has revealed the problem which is that you are setting this expression on the Format property of the textbox rather than its Value. When using the Format property, you need to change the expression to the following:

{0:hh:mm:ss}
 Please give it a try and let me know if that helps.

 

Austin
Top achievements
Rank 2
Iron
Iron
Iron
commented on 08 Sep 2023, 03:16 PM

Hi Dimitar,

I tried what you said. It is showing up now in the correct format but only shows the current date time. not the averages of the fields.

 

This is what I am averaging (=Avg(Fields.FINALDATETIME.TimeOfDay - Fields.COMPLETIONDATETIME.TimeOfDay))

 

If I put this with the format option I get the

 

However, if I replace it with

= Now().ToString("hh:mm:ss) 

 

it gives me the current time.

Dimitar
Telerik team
commented on 13 Sep 2023, 11:09 AM

Hi Austin,

Thank you for sending me the full expression!

In order to format the result returned from the Avg method, you need to slightly change the value set on the textbox's Format property:

{0:hh\:mm\:ss}

Alternatively, you could also do it using the ToString method like so:

= Avg(Fields.Date1.TimeOfDay - Fields.Date2.TimeOfDay).ToString("hh\:mm\:ss")

Both approaches are valid so feel free to use whichever you prefer. I hope this will help.

Tags
Conditional Formatting DataSource SQL Expressions General Discussions Report Designer (standalone) Report Parameters Sorting
Asked by
Austin
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Dimitar
Telerik team
Share this question
or