Datetime format in label only works for date

I have a small problem. I have a datagrid that I have a template in that shows a datetime field from a database table. The date format works fine, but when I just try a time only format I get 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

The datagrid shows this:

No overload for method 'ToString" Takes 1 arguments
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.

${data.EventScheduledDate.ToString("MM/dd/yyyy")} works but

${data.EventScheduledDate.ToString("hh:mm tt")} does not.

Also if I let the program create the to string

I get the same errors...

Is there a work around I am not seeing?

The problem is that your property is nullable DateTime and its ToString method is not the same as regular DateTime's.

You can try one of the following:

${data.EventScheduledDate?.ToString("hh:mm tt")}

or

${data.EventScheduledDate != null ? data.EventScheduledDate.Value.ToString("hh:mm tt") : ""}

1 Like

perfect thank you for the help!