Every time that I create a non-nullable datetime in my mvc3 application it defaults to now(), where now is current date with current time. I would like to default it to today’s date with 12am as the time.
I’m trying to default the time in my mvc…but…the following isn’t setting to todays date @12am. Instead it defaults to now with current date and time.
private DateTime _Begin = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 12, 0, 0);
public DateTime Begin { get { return _Begin; } set { _Begin = value; } }
How can I set to 12am for the current date for non-nullable datetime?
You can use the
Dateproperty of the DateTime object – egSo your code example becomes
PS. going back to your original code setting the hours to 12 will give you time of noon for the current day, so instead you could have used 0…