How do I format a date pulled from a database?

2019-09-04 19:29发布

问题:

I am trying to pull a date from database and putting it on a webpage with the below code:

<asp:Label ID="Label3" runat="server" Text='<%# Eval("TravelDate") %>' /><br /><br />

It pulls the date with no problem, but when it shows up on the page, no matter how it is formatted in the database, it seems to want to always display the date as "6/17/2013 12:00:00am". Is there something I'm missing in the VS portion that I have to use to format the date? I'd prefer "June 17, 2013", but the only option close to that in Access is where it adds the day of the week in front of it. Getting rid of the time is important.

回答1:

<asp:Label ID="txtDate" Width="65px" runat="server" Font-Size="8.5pt" ForeColor="#000f9f"
                                                            Text='<%# Eval("How_date","{0:dd/MMM/yyyy}") %>'></asp:Label>


回答2:

Try to extract like the field like this:

Expr1:Format([Field Name],"DD/MM/YYYY")

or

If it's a text field then you can use the string function left() or right() to get the date. Expr1:Left([Field Name],10)



回答3:

Just remove the single quotation mark '' after the property text of the TextBox.

<asp:Label ID="Label3" runat="server" Text=<%# Eval("TravelDate", "{0:MMMM dd, yyyy}") %> /><br /><br />