DateUtilsCalculateOccurrenceDate Method

This method is used to calculate the date on which a specific occurrence of any of a set of days occurs (for example, the 4th weekday in November or the last weekend day in January).

Definition

Namespace: EWSoftware.PDI
Assembly: EWSoftware.PDI (in EWSoftware.PDI.dll) Version: 2023.1.2.0
public static DateTime CalculateOccurrenceDate(
	int year,
	int month,
	DayOccurrence occur,
	DaysOfWeek days,
	int offset
)

Parameters

year  Int32
The year in which the day occurs
month  Int32
The month in which the day occurs
occur  DayOccurrence
The occurrence of the day of the week on which the day falls
days  DaysOfWeek
The day(s) of the week on which the day can occurs
offset  Int32
The number of days before or after the calculated date on which the day falls

Return Value

DateTime
Returns a DateTime object that represents the date calculated from the settings.

Remarks

This method is intended for use in finding an occurrence of any one of a set of days of the week and is normally used with the Weekdays or Weekends day of week value. However, the days of week parameter can be any valid combination of days including an individual day of the week.

Use a positive value for the nOffset parameter for a number of days after the calculated date or a negative number for a number of days before the calculated date.

Normally, this value will be zero so that the calculated date is the actual date returned. However, in cases where a date is calculated in terms of the number of days before or after a given date, this can be set to the offset to adjust the calculated date. Note that if used, the date returned may not be on one of the days of the week specified to calculate the original unadjusted date.

Example

C#
// Returns 01/06/2004 (fourth weekday in Jan 2004)
dtFourthWeekday = DateUtils.CalculateOccurrenceDate(2004, 1,
    DayOccurrence.Fourth, DaysOfWeek.Weekdays, 0);

// Returns 01/08/2004 (fourth weekday plus 2 days)
dtPlusTwo = DateUtils.CalculateOccurrenceDate(2004, 1,
    DayOccurrence.Fourth, DaysOfWeek.Weekdays, 2);

Exceptions

ArgumentExceptionThis is thrown if None is passed for the DayOccurrence parameter.

See Also