0

How do I format my vb.net mvc date to a shortdate in my view

    <td>
        <%: Html.DisplayFor(Function(modelItem) currentItem.DateCreated)%>
    </td>

1 Answer 1

1

Format(date, "MM/dd/YYYY")

I don't know what modelItem is, but i think you are looking to do this

<td>
    <%: HTML.DisplayFor(Function(modelItem), Format(currentItem.DateCreated, "MM/dd/YYYY")) %>
</td>

Not sure if thats right, i don't really know what Html.DisplayFor actually does. I've never ran into that before. But the Format(yourdate, shortdateformat) will definitely work

Sign up to request clarification or add additional context in comments.

2 Comments

I'm getting the following error: System.InvalidOperationException was unhandled by user code Message=Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.
Would you mind updating your original post with what modelItem does? Also, is currentItem.DateCreated just the date you want to format? If so you can probably get away with a <%= currentItem.DateCreated.Tostring("MM/dd/YYYY") %>

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.