DateTime.Now - first and last minutes of the day

Viewed 44687

Is there any easy way to get a DateTime's "TimeMin" and "TimeMax"?

TimeMin: The very first moment of the day. There is no DateTime that occurs before this one and still occurs on the same day.

TimeMax: The very last moment of the day. There is no DateTime that occurs after this one and still occurs on the same day.

These values would be helpful for filtering and doing date-related queries.

10 Answers
DateTime.Today.AddDays(1).AddSeconds(-1);

Not very exact, but fixed my problems. Now we can use AddMilliseconds, AddTicks and etc. I think it will just vary on what would satisfy your need.

Related