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?
Join Stack Overflow to learn, share knowledge, and build your career.
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?
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>
You can try this -
<asp:HyperLink ID="lnkCreatedDate1" runat="server" Text='<%# DateTime.Parse(Eval("CREATED_ON").ToString()).ToString("d") %>'> </asp:HyperLink>
this should do the trick:
<asp:HyperLink ID="lnkCreatedDate" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "CREATED_ON", "{0:dd/MM/yyyy}") %>'></asp:HyperLink>
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
You Can try THis Also
<asp:HyperLink ID="lnkCreatedDate" runat="server" Text='<%#Eval("CREATED_ON", "{0:d}")%>'> </asp:HyperLink>
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>