You must Sign In to post a response.
  • Category: ASP.NET

    How to give date format in Gridview???

    I have one date column in the table. When i bind the gridview with that table , the date column is showing the default time also. But i want to show only date not the time.
    for eg:

    It is showing like :
    7/18/2012 12:00:00 AM

    So in this i want only 7/18/2012.

    So pls suggest some solution.. Pls help...

    Thanks in Advance...
  • #680978
    hi you can use

    <asp:BoundField DataField="Date" HeaderText="Date" HtmlEncode="false" DataFormatString="{0:d}" />

    Or you can bind date like
    <asp:Label ID="labeldate" runat="server" Text='<%#Eval("Date1","{0:d}") %>'/>

    hope this will help you

  • #680982
    <asp:BoundField DataField="Date" HeaderText="Date" HtmlEncode="false" DataFormatString="{0:D}" />

    <asp:Label ID="labeldate" runat="server" Text='<%#Eval("Date1","{0:D}") %>'/>

    check..its working friend

  • #680986
    Dear Vish

    <asp:BoundField DataField="Date" HeaderText="Date" HtmlEncode="false" DataFormatString="{0:d}" />

    The following table shows some date format strings that can be used to format date in GridView columns,

    Format Pattern Name Example
    d Short date 11/8/2008
    D Long date Sunday, August 11, 2008
    t Short time 3:32 PM
    T Long time 3:32:00 PM
    f Full date/time Sunday, August 11, 2008 3:32 PM
    F Full date/time (long time) Sunday, August 11, 2008
    3:32:00 PM
    g General date/time (short time) 8/11/2008 3:32 PM
    G General date/time (long time) 8/11/2008 3:32:00 PM
    m or M Month day August 11
    r or R RFC 1123 Sun, 11 Aug 2008 8:32:00 GMT
    s Sortable date/time 2008-08-11T15:32:00
    u Universable sortable date/time 2008-08-11 15:32:00z
    U Universable sortable date/time Sunday, August 11, 2008
    11:32:00 PM
    y or Y Year month August, 2008


  • #681085

    another option you can convert in query itself like below

    select convert(CHAR(10),datefield,101) from tablename

    101 - mm/dd/yyyy
    102 -
    103 - dd/mm/yyyy
    104 -
    105 - dd-mm-yyyy
    106 - dd mon yyyy
    107 - Mon dd, yyyy
    110 - mm-dd-yyyy
    111 - yyyy/mm/dd
    112 – yyyymmdd

    Your Hard work never fails

  • #681185
    <asp:Label ID="labeldate" runat="server" Text='<%#Eval("Date1","{0:D}") %>'/>

    this s the answer

  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.