C# .NET: Get Min or Max DateTime for a Specific Date

11/25/2013 9:50:12 PM

.NET Framework

I sometimes need to get todays date (or any date) at its min (ex: 11/25/2013 12:00:00:00 AM) or at its max (ex: 11/25/2013 11:59:59:59 PM). This is often associated with a database call. The following 2 methods accomplish this.

public static DateTime Get_MinDaysDateTime(DateTime dateTime)
{
	return new DateTime(dateTime.Year, dateTime.Month, dateTime.Day);
}


public static DateTime Get_MaxDaysDateTime(DateTime dateTime)
{	
	return new DateTime(dateTime.Year, dateTime.Month, dateTime.Day).AddDays(1).AddSeconds(-1);
}