I have a model for my database that has a DateTime property. However, this property is really a Date. The extra time component is causing issues when sorting/filtering on the client. Many tables/client components have this problem.
I was hoping I could fix this at the model level, and only retrieve the Date portion whenever it is accessed with the following modification.
private DateTime invoiceDate;
[Required]
public DateTime InvoiceDate { get => invoiceDate.Date; set =>invoiceDate = value; }
However, this does not seem to be working. Is something like this possible?
Edit: I have discovered C# allows more specific DataType specifications on models - https://learn.microsoft.com/en-us/aspnet/mvc/overview/getting-started/getting-started-with-ef-using-mvc/creating-a-more-complex-data-model-for-an-asp-net-mvc-application
i.e.
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateTime EnrollmentDate { get; set; }
However, when I hit my API I am still getting the full database information
"InvoiceDate": "2019-06-14T00:00:00-07:00"
Why isn't C# fixing this with the extra specification provided?
Edit:
I have also found this helpful thread which suggested adding a JSON converter to the property, but that has not fixed the problem either. The time is still being sent.