maqskywalker
asked on
formatting a datetime field in a razor DisplayFor tag
Hi experts,
I'm using ASP.NET MVC 5 with C#
On my view I have a DisplayFor displaying a datetime field.
My date time field is stored in sql server as datetime format
This is my current razor for this label on my page.
@Html.DisplayFor(m => m.MyTestDate)
With this syntax the browser displays this on my page.
07/17/2017 07:30:00 AM
Question 1: How do I format the razor DisplayFor tag to display only the date like this?:
07/17/2017
Question 2: How do I format the razor DisplayFor tag to display only the time like this?:
07:30:00 AM
I'm using ASP.NET MVC 5 with C#
On my view I have a DisplayFor displaying a datetime field.
My date time field is stored in sql server as datetime format
This is my current razor for this label on my page.
@Html.DisplayFor(m => m.MyTestDate)
With this syntax the browser displays this on my page.
07/17/2017 07:30:00 AM
Question 1: How do I format the razor DisplayFor tag to display only the date like this?:
07/17/2017
Question 2: How do I format the razor DisplayFor tag to display only the time like this?:
07:30:00 AM
try
Custom Date and Time Format Strings
https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings
datetime1.ToString("MM/dd/yyyy")
datetime2.ToString("hh:mi:ss t")
Custom Date and Time Format Strings
https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks
SELECT (CONVERT,yourcolumn,101)
SELECT CAST( yourcolumn AS TIME )