I have used following code :
<asp:HyperLink ID="Time" runat="server" Text='<%#Eval("CREATED_ON")%>'> </asp:HyperLink>
It will display the date in the format: 11/4/2010 10:52:33 AM
But I want it to display 11/4/2010. How would I do this?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
You should be able to use something like this:
<asp:HyperLink ID="lnkCreatedDate" runat="server" Text='<%#Eval("CREATED_ON", "{0:dd/M/yyyy}")%>'> </asp:HyperLink>
Method 2
You can try this –
<asp:HyperLink ID="lnkCreatedDate1" runat="server" Text='<%# DateTime.Parse(Eval("CREATED_ON").ToString()).ToString("d") %>'> </asp:HyperLink>
Method 3
this should do the trick:
<asp:HyperLink ID="lnkCreatedDate" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "CREATED_ON", "{0:dd/MM/yyyy}") %>'></asp:HyperLink>
Method 4
I suppose you have a DateTime variable named MyDate:
DateTime MyDate;
If you want juste the date part:
MyDate.Value.ToString("d");
With the day:
MyDate.Value.ToString("D");
Here is a usefull doc PDF Doc
Method 5
You Can try THis Also
<asp:HyperLink ID="lnkCreatedDate" runat="server" Text='<%#Eval("CREATED_ON", "{0:d}")%>'> </asp:HyperLink>
Method 6
- I Was Face Problem When Date Is NULL.
- It Will Help Me When CREATED_ON Date Is Null.
-
Use This Code When You Are Not Sure That Your Date Is NULL OR NOT.
<asp:HyperLink ID="lnkCreatedDate1" runat="server" Text='<%# (String.IsNullOrEmpty(Eval("CREATED_ON").ToString())) ? "" : DateTime.Parse(Eval("CREATED_ON").ToString()).ToString("d") %>'></asp:HyperLink>
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0