Class DateTimeExtensions
This class implements two overloads of DateOfMostRecentWeekdayDay, a static method, implemented as an extension method on the System.DateTime type. The two overloads accept their one externally visible argment as either a DayOfWeek enumeration member or its integral value.
Inheritance
Namespace: WizardWrx
Assembly: WizardWrx.Core.dll
Syntax
public static class DateTimeExtensions : object
Methods
| Improve this Doc View SourceDateOfMostRecentWeekday(DateTime, DayOfWeek)
Given a date and a day of the week, return the date of the most recent instance of the specified day of the week.
Declaration
public static DateTime DateOfMostRecentWeekday(this DateTime pdtmThisDate, DayOfWeek penmDayOfWeek)
Parameters
Type | Name | Description |
---|---|---|
DateTime | pdtmThisDate | Specify the DateTime to serve as the reference point against which
calculate the most recent weekday given by |
DayOfWeek | penmDayOfWeek | Specify the weekday in terms of the DayOfWeek enumeration for which the
weekday nearest to |
Returns
Type | Description |
---|---|
DateTime | The return value is the date, represented as a DateTime object, for
which the DayOfWeek property is the value specified by
|
Remarks
Since enumerated types can be freely converted to and from integers, and a program stands a fair chance of having the weekday specified in terms of either, two versions of this method are offered. Since integers are easier to manipulate, the overload that accepts the integer representation of the weekday implements both; the overload that takes the enumeration casts it to integer and calls the other overload, through which it returns.
Examples
When pdtmThisDate
is 03/08/2022 and
penmDayOfWeek
is Sunday, the return value is
Sunday, 03/06/2022.
DateOfMostRecentWeekday(DateTime, Int32)
Given a date and a day of the week, return the date of the most recent instance of the specified day of the week.
Declaration
public static DateTime DateOfMostRecentWeekday(this DateTime pdtmThisDate, int pintDayOfWeekIndex)
Parameters
Type | Name | Description |
---|---|---|
DateTime | pdtmThisDate | Specify the DateTime to serve as the reference point against which
calculate the most recent weekday given by |
System.Int32 | pintDayOfWeekIndex | Specify the weekday in terms of the integer that maps to the intended
DayOfWeek enumeration value for which the weekday nearest to
|
Returns
Type | Description |
---|---|
DateTime | The return value is the date, represented as a DateTime object, for
which the DayOfWeek property is the value specified as integer
|
Remarks
Since enumerated types can be freely converted to and from integers, and a program stands a fair chance of having the weekday specified in terms of either, two versions of this method are offered. Since integers are easier to manipulate, the overload that accepts the integer representation of the weekday implements both; the overload that takes the enumeration casts it to integer and calls the other overload, through which it returns.
Examples
When pdtmThisDate
is 03/08/2022 and
pintDayOfWeekIndex
is Sunday, the return value is
Sunday, 03/06/2022.