Grid FormatString question

Trying some time formats like "{hh:mm:ss tt}" in the DataGrid column FormatString and I keep getting "invalid format string". It's bound to a time span.

Looking for a 12hr time format string that works? Or do I have to template this?

Thanks!

Hi @terryfryar,

Try something like {0:hh:mm:ss tt}. Radzen passes the FormatString to string.Format

<RadzenDataGridColumn TItem="WebCmDemo.Models.MainDataSource.CallRule" FormatString="{0:hh:mm:ss tt}" Property="START_TIME" Title="START TIME">

Got this error: System.FormatException: Input string was not in a correct format.

Schema was "Time" field in MSSQL, which was inferred as:

public TimeSpan? START_TIME
{
get;
set;
}

You probably have to escape the ':' as suggested here: Custom TimeSpan format strings | Microsoft Docs

Tried these...same error....

<RadzenDataGridColumn TItem="WebCmDemo.Models.MainDataSource.CallRule" FormatString="{0\:hh\:mm\:ss tt}" Property="START_TIME" Title="START TIME">

<RadzenDataGridColumn TItem="WebCmDemo.Models.MainDataSource.CallRule" FormatString="{0\\:hh\\:mm\\:ss tt}" Property="START_TIME" Title="START TIME">

Oddly enough, {0:t} works fine?

The first colon should not be escaped. This should work: "{0:hh\\:mm\\:ss}". The string tt does not seem to be valid format string for TimeSpan values.

Found this page, and you are correct: Custom TimeSpan format strings | Microsoft Docs

I see that TimeSpan has no concept of AM/PM...as it's just a duration? Well, I'll have to rethink my schema I guess...thank you for the help!

Also, I assume using a DatePicker with "time only" bound to a TimeSpan would not work correctly?

I don't think DateTime picker would work correctly with a TimeSpan. I recommend using DateTime.