Class DateTimeExtensions
Extensions that provide utility methods for the DateTime struct.
public static class DateTimeExtensions
- Inheritance
-
DateTimeExtensions
- Inherited Members
Methods
IsOnDayOfWeek(DateTime, IEnumerable<DayOfWeek>)
Checks if the day of week component of the given DateTime falls on any of the specified days of week.
public static bool IsOnDayOfWeek(this DateTime dateTime, IEnumerable<DayOfWeek> dows)
Parameters
dateTimeDateTimedowsIEnumerable<DayOfWeek>
Returns
IsOnDayOfWeek(DateTime, IEnumerable<string>)
Checks if the day of week component of the given DateTime falls on any of the specified days of week (case-insensitive, supports both full and abbreviated day of week names).
public static bool IsOnDayOfWeek(this DateTime dateTime, IEnumerable<string> dows)
Parameters
dateTimeDateTimedowsIEnumerable<string>
Returns
IsOnDayOfWeek(DateTime, params DayOfWeek[])
Checks if the day of week component of the given DateTime falls on any of the specified days of week.
public static bool IsOnDayOfWeek(this DateTime dateTime, params DayOfWeek[] dows)
Parameters
Returns
IsOnDayOfWeek(DateTime, params string[])
Checks if the day of week component of the given DateTime falls on any of the specified days of week (case-insensitive, supports both full and abbreviated day of week names).
public static bool IsOnDayOfWeek(this DateTime dateTime, params string[] dows)
Parameters
Returns
IsWithinTimeWindow(DateTime, TimeOnly, TimeOnly)
Checks if the time component of the given DateTime falls within the specified time window (e.g. start <= dateTime < end).
public static bool IsWithinTimeWindow(this DateTime dateTime, TimeOnly startInclusive, TimeOnly endExclusive)
Parameters
Returns
Remarks
The time window can span across midnight. For example, a time window from 22:00 to 02:00 will include times from 22:00 to 23:59 and from 00:00 to 02:00.
NextWeekDay(DateTime)
Returns a new DateTime representing the next weekday (Monday to Friday) of the given DateTime.
public static DateTime NextWeekDay(this DateTime dateTime)
Parameters
dateTimeDateTime
Returns
PrevWeekDay(DateTime)
Returns a new DateTime representing the previous weekday (Monday to Friday) of the given DateTime.
public static DateTime PrevWeekDay(this DateTime dateTime)
Parameters
dateTimeDateTime
Returns
StartOfDay(DateTime)
Returns a new DateTime with the time component set to 00:00:00
public static DateTime StartOfDay(this DateTime dateTime)
Parameters
dateTimeDateTime