DateUtilsDateFromWeek Method

This method returns a date calculated from a year, a week number, and the day on which weeks start

Definition

Namespace: EWSoftware.PDI
Assembly: EWSoftware.PDI (in EWSoftware.PDI.dll) Version: 2023.1.2.0
public static DateTime DateFromWeek(
	int year,
	int week,
	DayOfWeek dow,
	int offset
)

Parameters

year  Int32
The year containing the week
week  Int32
The week of the year
dow  DayOfWeek
The day on which a week starts
offset  Int32
An additional offset in days to add to the week start date

Return Value

DateTime
Returns the calculated date.

Remarks

A week is defined as a seven day period starting on the specified day of the week. The first week of the year is defined as the one starting on the specified day of the week and containing at least four days of the year.

If the year starts on a day of the week later than the one specified, this may return a date a few days earlier than January 1st of the specified year for week 1.

Not all years will have a 53rd week. For example, assuming a Monday week start, week 53 can only occur when Thursday is January 1st or if it is a leap year and Wednesday is January 1st. It is up to the caller to determine this and discard the date. WeeksInYear(Int32, DayOfWeek) can be used to determine this condition.

Example

C#
// Returns Monday 12/29/1997 because 01/01/1998 falls on a Thursday
dtDate = DateUtils.DateFromWeek(1998, 1, DayOfWeek.Monday, 0);

// Returns 08/27/2003
dtDate = DateUtils.DateFromWeek(2003, 35, DayOfWeek.Wednesday, 0);

Exceptions

ArgumentOutOfRangeExceptionAn exception is thrown if the week value is not between 1 and 53.

See Also