Jude
Jude

Reputation: 2433

ASP.NET Displaying Date in Label

<asp:Label ID="Label1" runat="server" Text='<%# Bind("Date") %>'></asp:Label>

Displays

03.06.2014 10:30:00

How can I display it as 3 Jun 2014 10:30

Upvotes: 7

Views: 34725

Answers (5)

Arion
Arion

Reputation: 31249

Maybe something like this:

Bind("Date").ToString("d MMM yyyy hh:mm")

You could also do this:

string.Format("{0:d MMM yyyy hh:mm}",Bind("Date"))

Upvotes: 1

Liath
Liath

Reputation: 10191

Try this:

Text='<%# Eval("Date", "{d MMM yyyy hh:mm}") %>'

You can see more format strings here.

Upvotes: 3

Ali
Ali

Reputation: 2592

this would display

<asp:Label ID="Label1" runat="server" 
           Text='<%# ((DateTime)Bind("Date")).ToString("f", System.Globalization.CultureInfo.CreateSpecificCulture("en-US")) %>'></asp:Label>

Upvotes: 0

Tim Schmelter
Tim Schmelter

Reputation: 460208

This should work:

<asp:Label ID="Label1" runat="server" 
    Text='<%# Eval("Date", "{0:d MMM yyyy HH:mm}") %>'>
</asp:Label>

See: Custom Date and Time Format Strings

Upvotes: 21

Sid M
Sid M

Reputation: 4354

Try this

<asp:Label ID="Label1" runat="server" 
Text='<%# Bind("Date").ToString("d MMM yyyy hh:mm:ss",CultureInfo.CreateSpecificCulture("en-US")) %>'>
</asp:Label>

ref: Custom date time formats

Upvotes: 1

Related Questions