locked
How to format the date in ListView? RRS feed

  • Question

  • User1841825477 posted

    In the database, I use the "date" datatype.
    I chose this datatype because all I want to record is the date not the time.

    However, the ListView column shows: 02/02/2018 00:00:00
    But I just want to show the date as dd,mmm,yyy OR dd,mm,yyyy

    I tried several different solutions but they all give "Server Error"
    For example::
    <asp:Label ID="dateLabel" runat="server" Text='<%# Eval(("date"),"{0.d}") %>' />

    I have wasted hours on this.
    Can someone please let me know how to format the date in ListView?

    Here are the relevant ListView rows:
    <asp:Label ID="dateLabel" runat="server" Text='<%# Eval("date") %>' />
    <asp:TextBox ID="dateTextBox" runat="server" Text='<%# Bind("date") %>' />

    Thanks

    Saturday, February 3, 2018 3:13 PM

Answers

  • User1841825477 posted

    OK - I found a solution for the asp:Label row:

    <asp:Label ID="dateLabel" runat="server" Text='<%# Eval("date", "{0:MMM d, yyyy}") %>' />

    Now for the  asp:Textbox line

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, February 3, 2018 3:36 PM