skip to Main Content

How can I modify the displayed date format in my database view to exclude the timestamp (00:00:00) and show only the date in the format (DD/MM/YYYY)?

<td>@marks["Test_Date"]</td>

I am fetching date here and i have tried like this

<td>@((DateTime)marks["Test_Date"]).ToString("dd/MM/yyyy")</td>

It didn’t work it just print the date like this
20/02/2024 00:00:00.ToString("dd/MM/yyyy")

2

Answers


  1. Chosen as BEST ANSWER

    after some times i figure it out the answer is @DateTime.Parse(marks["Test_Date"].ToString()).ToString("dd/MM/yyyy")

    it works for me it return this output 20/02/2024


  2. If you want to format a DateTime value with a custom format, you must follow the rules laid out by the custom date and time format strings. For instance, the character / is used to indicate "The date separator", which may turn out to be another character than /, depending on the executing process’ underlying locale.

    If you want to force the format to use / you can escape it:

    new DateTime(2024, 2, 20).ToString("dd/MM/yyyy");
    

    This expression produces the string "20/02/2024".

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search