New to Telerik Reporting? Download free 30-day trial

How to Format MS SQL Time Data Type and .NET TimeSpan Object

Environment

Product Progress® Telerik® Reporting

Description

If you try to format an MS SQL Time data type with the standard or custom DateTime format strings, the layout may be incorrect, or there may be an error like:

An error has occurred while processing TextBox 'textBox13':
An error has occurred while executing function FormatWithCulture(). Check the InnerException for more information.
------------- InnerException -------------
Exception has been thrown by the target of an invocation.
------------- InnerException -------------
Input string was not in a correct format.

Solution

The Time MS SQL data type is converted to TimeSpan .NET type by the corresponding ADO.NET providers. For that reason, you need to use the TimeSpan formatting. For example, for a short time consider {0:hh\:mm} and for a long time you may use {0:g}. It is not possible to use formatting with 'AM' and 'PM', as the TimeSpan structure represents a time difference.

In this article