Format Datetime

Hello,

I am attempting to format a datetime value to "HH:mm:ss" using the ToString method on a child data grid. As shown below, the Setup Time and Time Per Part columns are displaying the full datetime.

The current template for those columns are ${data.ProductionTime?.SetupTime} and ${data.ProductionTime?.TimePerPart} respectively with no 'FormatString' options available as shown below.

When I alter the template to read ${data.ProductionTime?.SetupTime.ToString("HH:mm:ss")} I receive the following error: "Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type".

I have used the ToString on the same column in a dropdown data grid successfully that read ${data.SetupTime.ToString("HH:mm:ss")}. The only difference I know of in that scenario is that I did not have to reference an expanded table.

What am I doing wrong? Please let me know if you require additional information, screenshots, or files.

Thank you,

Zach

Hi @Zach.E,

The issue is caused most probably by the null-conditional operator (?.). Can you try with normal member access (.) instead?

Hello @enchev, thank you for the reply!

I have entered ${data.ProductionTime.SetupTime.ToString("HH:mm:ss")} into the template and received the same error.

Hi @Zach.E,

Please zip and send us your application meta folder at info@radzen.com.

Hi @Zach.E,

The actual error can be seen when you open the generated code in Visual Studio:

You can use string.Format() instead:



This did indeed remove the error but inserted the value "HH:mm:ss" rather than format the datetime.

image

You are right. The correct expression should be: ${string.Format("{0:HH:mm:ss}", DateTime.Now)}

Thank works, thank you @enchev!

I am having a similar issue on the Edit Page of the same table. I would like the Text Property to display the datetime as "HH:mm:ss" rather than the full datetime as well. Here is the generated format that displays the full datetime.

When I use the Data-bind TextProperty interface and select the Data formatting option of Long Time as shown below, I receive errors.

image

This gives me the error "error CS1501: No overload for method 'ToString' takes 1 arguments [C:\dev\BlazorProductionTime\server\ProductionTimeTracker.csproj]

dotnet: C:\dev\BlazorProductionTime\server\Microsoft.NET.Sdk.Razor.SourceGenerators\Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator\Pages_EditPartRouting_razor.g.cs(117,174): error CS1662: Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type [C:\dev\BlazorProductionTime\server\ProductionTimeTracker.csproj]"

I also receive errors when I edit the text property to read either:

${string.Format("{0:HH:mm:ss}", partrouting.ProductionTime.TimePerPart)}

or

${partrouting.ProductionTime.TimePerPart.ToString("HH:mm:ss")}

Any help would be appreciated. Thank you!

As we already discussed there is no ToString() with format. You cannot also use such expressions for TextProperty - this is a string property name. You should define Template.