1

I have the following code: <%= Html.Encode(String.Format("{0:g}", item.startDate)) %>

It outputs something like 01/01/2011 00:00 but I would to ONLY show the date and not the time! How can I do this? Thanks

3 Answers 3

4

Try

<%= Html.Encode(String.Format("{0:d}", item.startDate)) %>
Sign up to request clarification or add additional context in comments.

Comments

4
<%= item.startDate.ToShortDate() %>

The above will take into account the current Locale and format it as the locale dictates. There is also no point in using Html.Encode() since it's impossible for the output of the date function to contain anything dangerous that needs encoding.

Comments

1
<%= Html.Encode(item.StartDate.ToString("dd/MM/yyy")) %>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.