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
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
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:This expression produces the string
"20/02/2024"
.