Reputation: 143
I have a requirement to validate a mandatory datetime field but allow midnight. I am using MVC to bind the property (which is part of my model).
It the user has typed in midnight as the time, then i create an instance of DateTime as follows:
result = New DateTime(Year, Month, Day, Time.Hour, Time.Minute, Time.Second)
if the user has not specified a time, then i create it as follows:
result = New DateTime(Year, Month, Day)
My question is, when validating, is there a way to tell that time was specified (even if that time is set to midnight) on my result property?
Upvotes: 1
Views: 132
Reputation: 6845
From a DateTime variable there is no way to tell that the time was specified or not. A DateTime is a Date and a Time.
When you create a DateTime without specifying the time, the Time part is automatically 00:00:00. So there is no difference with a DateTime created with a time of midnight.
Upvotes: 1