DateUtilsCalculateFloatingDate Method

This method is used to calculate the date on which a floating day occurs (for example, the 4th Thursday in November).

Definition

Namespace: EWSoftware.PDI
Assembly: EWSoftware.PDI (in EWSoftware.PDI.dll) Version: 2023.1.2.0
public static DateTime CalculateFloatingDate(
	int year,
	int month,
	DayOccurrence occur,
	DayOfWeek dowDay,
	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.
dowDay  DayOfWeek
The day of the week on which the day occurs.
offset  Int32
The number of days before or after the calculated date on which the day actually falls.

Return Value

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

Remarks

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.

For example, to calculate the day after Thanksgiving, the value of this parameter would be set to 1 (one day after Thanksgiving, which is the 4th Thursday in November). You cannot use the 4th Friday to calculate the date because if the month starts on a Friday, the calculated date would be a week too early. As such, the nOffset parameter is used instead.

Example

C#
// Returns 11/28/2002 (Thanksgiving)
dtThanksgiving = DateUtils.CalculateFloatingDate(2002, 11,
    DayOccurrence.Fourth, DayOfWeek.Thursday, 0);

// Returns 11/29/2002 (Day after Thanksgiving)
dtDayAfterTG = DateUtils.CalculateFloatingDate(2002, 11,
    DayOccurrence.Fourth, DayOfWeek.Thursday, 1);

// Returns 11/22/2002 (Fourth Friday isn't after the fourth
// Thursday in 2002 hence the use of the nOffset parameter
// in the call above).
dtFourthFri = DateUtils.CalculateFloatingDate(2002, 11,
    DayOccurrence.Fourth, DayOfWeek.Friday, 0);

Exceptions

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

See Also