locked
DateFormatting on a view RRS feed

  • Question

  • User1266884534 posted

    I wish to format the date being displayed on my view. I am using this code to display it

    <div class="col text-right">@rec.InvoiceDate</div>

    This leads to the following output. 6/28/2019 3:12:07 PM

    I am aware of the .ToString("d") method, but that doesn't work here since the InvoiceDate is a nullable datetime field.

    Is there some kind of formatting that can be applied on the View page? I cannot control the service that is sending me this data.

    Friday, August 23, 2019 4:58 PM

Answers

  • User1266884534 posted

    This is what I did.

    <div class="col text-right">@(rec.InvoiceDate.HasValue ? string.Format(rec.InvoiceDate.Value.ToString("MM/dd/yyyy")) : "--/--/----")</div>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, August 23, 2019 5:11 PM