Hi I'm trying to format a datetime field to just show the date. The datetime is bound to an asp:label and for the Text attribute I have tried the following....

Text= String.Format("{0:D}", '<%# Bind("CReviewDate") %>')
and
Text= String.Format("{0:D}", <%# Bind("CReviewDate") %>)
and 
Text= String.Format("{0:D}", <%# Bind('CReviewDate') %>)
and
Text= String.Format("{0:D}", <%# Bind(CReviewDate) %>)

In all cases I get a green wavy line under the equation and the tip help says "Validation (ASP.Net): If this attribute value is enclosed in quotation marks, the quotation marks must match.

String.Format("{0:D}", DateTime.Now)

is the syntax that I have been told should work.
What have I done wrong....
I've not failed! Just found 100 (well 4) ways that don't work...yet!

Edited 6 Years Ago by Mych: n/a

Instead of String.Format(...) have you tried DateTime.Now.ToString("<date format string>") .
Where <date format string> can be any combination of date and time formats.

Or perhaps something dirty like this?

Text= <%# Bind(CReviewDate) %>
Text= DateTime.Parse(Text).ToString("yyyy-MM-dd")

Thanks Oxiegen.... As I'm still a novice I was hoping to stay simple and not have to use code to populate the label. It binds to the data from the db but to keep the display looking simple I just wanted to display the date with no time....
Mych

This article has been dead for over six months. Start a new discussion instead.