Xbasic

WEEK_ISO Function

Syntax

Week_Number as N = week_iso(date as D)

Arguments

dateDate

The date to be analyzed.

Returns

Week_NumberNumeric

Returns the ISO week number of the year where Monday is the first day of the week. Dates at the beginning or end of a calendar year may be included in the week for the previous or next year, respectively.

Description

Get the ISO calendar week number for a date where Monday is the first day of the week.

Discussion

The WEEK_ISO() function returns the ISO 8601 week number of the year where Monday is the first day of the week. Week numbers are 1 to 52 or 53. Part of week 1 may include dates from the previous calendar year. Part of week 52 or 53 may include dates from the next calendar year.

The first week of the year is calculated as the week containing the first Thursday of the calendar year. This implies the following:

  • The first week is mostly within the calendar year.
  • The first week contains January 4th.
  • The first week starts with the Monday nearest January 1st.

The last week of the year is the week containing the last Thursday of the calendar year. The following statements are also true of the last week of the year:

  • The last week of the year is mostly within the calendar year.
  • The last week contains December 28th.
  • The last week ends with the Sunday nearest to December 31st.
dim start as D = {1/1/2005}
? cdow(start)
= "Saturday"

? week_iso(start)
= 53

? week_iso(start+1)
= 53

? week_iso(start+2)
= 1

? cdow(start+2)
= "Monday"

See Also