DateTimeExtensionsOrdinalDate(OrdinalWeekday, DayOfWeek, Int32, Int32, Int32) Method

Returns the date of the nth occurrence of a particular weekday in a given month.

Definition

Namespace: InnerDrive.Core
Assembly: InnerDrive.Core (in InnerDrive.Core.dll) Version: 5.2.9017.0
C#
public static DateTime OrdinalDate(
	OrdinalWeekday occurrence,
	DayOfWeek dayOfWeek,
	int year,
	int month,
	int day
)

Parameters

occurrence  OrdinalWeekday
The number of the occurrence.
dayOfWeek  DayOfWeek
The day of week to use.
year  Int32
The calendar year to use.
month  Int32
The month to use, where 1 = January and 12 = December.
day  Int32
The day of the month to use as the lower limit of the result. (See remarks.)

Return Value

DateTime
A DateTime structure representing the date sought.

Remarks

The day parameter is the lower limit of the day of the month to use. In other words, you can find the first occurrence of a weekday after a particular day using this overload by supplying the following day for the day parameter.

If the value of day is greater than the last occurrence of dayOfWeek, the last occurrence is returned.

The following table shows the output of the OrdinalDate method:

occurrencedayOfWeekyearmonthdayResult
FirstMonday20141012014-10-06
FirstTuesday20141112014-11-04
FirstTuesday20051122005-11-08
FourthTuesday200511302005-11-29
ExactTuesday20041132006-11-03

Example

C#
var electionDay = 
DateTimeExtensions.OrdinalDate(OrdinalWeekday.Second, DayOfWeek.Tuesday, 2014, 11, 1);

// Result: 2014-11-04

See Also