Format TimeSpan column in OnExcelBeforeExport

1 Answer 36 Views
Grid
Dean
Top achievements
Rank 1
Iron
Veteran
Iron
Dean asked on 09 Mar 2023, 03:09 PM

Hi, I have a grid with a nullable TimeSpan column.  When exporting to Excel the format shows as 09:02:39.  I'd like it just to be 09:02. In OnExcelBeforeExport I have args.Columns[3].NumberFormat = BuiltInNumberFormats.GetHourMinuteAMPM(); but it has no effect.  Should it?

1 Answer, 1 is accepted

Sort by
0
Nadezhda Tacheva
Telerik team
answered on 14 Mar 2023, 01:56 PM

Hi Dean,

The GetHourMinuteAMPM() works with DateTime objects. It generates format with hours, minutes and AM/PM that indicates the specific part of the day.

The TimeSpan is generally used to indicate duration or difference between DateTime objects. It represents a time period and not a specific time of the day. Thus, the GetHourMinuteAMPM() built-in format is not applicable to it.

To achieve the desired result, I can suggest converting the TimeSpan values to DateTime prior to passing data to the Grid. Then, you can use the GetHourMinute() format.

I hope you will find the above information useful. Please let us know if any other questions appear.

Regards,
Nadezhda Tacheva
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Grid
Asked by
Dean
Top achievements
Rank 1
Iron
Veteran
Iron
Answers by
Nadezhda Tacheva
Telerik team
Share this question
or