2 using System.Collections.Generic;
8 public static class DateTimeExtensions
10 public static DateTime Limit(
this DateTime DateToLimit, DateTime MinDate, DateTime MaxDate)
12 if (DateToLimit < MinDate)
return MinDate;
13 if (DateToLimit > MaxDate)
return MaxDate;
17 public static DateTime? Limit(
this DateTime? DateToLimit, DateTime MinDate, DateTime MaxDate)
19 if (!DateToLimit.HasValue)
return null;
20 if (DateToLimit < MinDate)
return MinDate;
21 if (DateToLimit > MaxDate)
return MaxDate;
26 public static bool IsBetween(
this DateTime DateToCheck, DateTime MinDate, DateTime MaxDate)
28 return DateToCheck >= MinDate && DateToCheck <= MaxDate;
32 public static bool IsBetween(
this DateTime? DateToCheck, DateTime MinDate, DateTime MaxDate)
34 if (!DateToCheck.HasValue)
return false;
35 return DateToCheck.Value >= MinDate && DateToCheck.Value <= MaxDate;
38 public static DateTime FirstDayOfMonth(
this DateTime DateTime)
40 return new DateTime(DateTime.Year, DateTime.Month, 1);
44 public static DateTime LastDayOfMonth(
this DateTime DateTime)
46 return new DateTime(DateTime.Year, DateTime.Month, DateTime.DaysInMonth(DateTime.Year, DateTime.Month));