In an aspx page I am binding the labels like this:
&l
You can specify format strings for the eval statement:
Eval("date_of_joining", "{0:dd/MM/yyyy}")
You can use the DataFormatString in a bound field the same can be set as below:
<asp:Label ID="Label8" runat="server" Text='<%# Eval("paid_priviledge_date","{0:d}") %>'/>
Create a FormatDate
method in your codebehind, and call that from your gridview.
http://msdn.microsoft.com/en-us/library/8kb3ffffd4.aspx
http://www.csharp-examples.net/string-format-datetime/
This part will go in your code behind
private object FormatDate(DateTime input)
{
return String.Format("{0:MM/dd/yy}", input);
}
And this bit will go in your markup
<asp:TemplateField HeaderText="Date of Joining">
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# FormatDate(Eval("date_of_joining")) %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Paid Priviledge Date">
<ItemTemplate>
<asp:Label ID="Label8" runat="server"
Text='<%# FormatDate(Eval("paid_priviledge_date")) %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
This is what I would call a D.R.Y. approach to the problem. If you ever need to modify the formatting in any way. You can simply edit the code behind method and it will rain down sweet love to all of your markup.
Text='<%# (Convert.ToDateTime((Eval("date_of_joining")))).ToShortDateString() %>'
This is the simplest way I discovered.
Use "{0:d}"
for short date format.
Try
Text='<%# Eval("paid_priviledge_date","{0:d}") %>'
and
Text='<%# Eval("date_of_joining", "{0:d}") %>'