In an ASP.NET page I have this:
<asp:Label ID="MyDateTimeLabel" runat="server"
Text='<%# Eval("MyDateTime") %>' />
I’d like to have it formatted like
... Eval("MyDateTime", "{0:d}") ... // Display only the date
if and only if the time part of MyDateTime is 00:00:00. Otherwise like this:
... Eval("MyDateTime", "{0:g}") ... // Display date and time in hh:mm format
Is this possible and how can I do that?
Thank you for hints in advance!
I’d put this in my code-behind:
And change the .aspx to call that:
If you do this in multiple places, consider writing an extension method for
DateTimeand put this logic there (perhaps with additional parameters to supply different formats, etc.).