How do I format a date pulled from a database?

与世无争的帅哥 提交于 2019-12-12 03:09:53

问题


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 />


来源:https://stackoverflow.com/questions/17824427/how-do-i-format-a-date-pulled-from-a-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!