how to set date format in eval asp.net

RAVI 1,076 Reputation points
2025-02-25T08:36:02.3033333+00:00

Hello

this is my date eval <%#Eval("Date", "{0:dd/MMM/yyyy}")%> when i convert to excel i want excel filter to be look like this so what to change my eval so that it can look like as below111

Developer technologies | ASP.NET | ASP.NET API
{count} votes

3 answers

Sort by: Most helpful
  1. Anonymous
    2025-02-25T09:56:58.8266667+00:00

    Hi @RAVI

    date eval <%#Eval("Date", "{0:dd/MMM/yyyy}")%>

    If you want the date to be displayed in a format like "18-Feb-25", you need to set the format to dd-MMM-yy.

    1. dd : The day of the month, from 01 to 31.
    2. MMM : The abbreviated name of the month.
    3. yy : The year, from 00 to 99.

    In data bind, it should look like:

     <%# Eval("Date", "{0:dd-MMM-yy}") %>
    

    For more details about the date and time format, please refer to this doc: https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings

    Best regards,

    Xudong Peng


    If the answer is the right solution, please click "Accept Answer" and kindly upvote. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. RAVI 1,076 Reputation points
    2025-03-08T00:07:16.5833333+00:00

    try but after export to excel its not showing what i need as below

    1111

    what to set date format to show like this when i export to excel


  3. Jack Dang (WICLOUD CORPORATION) 1,020 Reputation points Microsoft External Staff
    2025-08-12T03:41:32.4933333+00:00

    Hi @RAVI,

    Thanks for reaching out.

    The current date eval format:

    <%#Eval("Date", "{0:dd/MMM/yyyy}")%>
    

    displays dates like 18/Feb/2025, but when exported to Excel, it may not align with the desired filter format (e.g., 18-Feb-25). Simply changing the Eval format to:

    <%# Eval("Date", "{0:dd-MMM-yy}") %>
    

    will adjust the display in the web page to 18-Feb-25.

    • dd: The day of the month, from 01 to 31.
    • MMM: The abbreviated name of the month.
    • yy: The year, from 00 to 99. To ensure the exported Excel file displays and filters dates as needed, the ASP.NET Eval method only formats the data for the web page and does not control Excel's column formatting. You should export the raw DateTime value (not a preformatted string) so Excel can store it as a true date. For proper Excel date formatting, you should use an Excel library such as Open XML to define the date format during the export process. This allows Excel to recognize the column as dates and apply filters like 18-Feb-25 correctly.

    For more details about date and time format strings, please refer to this doc: https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings

    Hope this helps! If you agree with my suggestion, feel free to interact with the system accordingly!

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.