Skip to main content

weekyear - script and chart function

This function returns the year to which the week number belongs according to ISO 8601. The week number ranges between 1 and approximately 52.



Return data type: integer

The weekyear() function determines which week of a year a date falls into. It then returns the year corresponding to that week number.

By default, Qlik apps use broken weeks (defined by the BrokenWeeks system variable) and week number 1 begins on January 1 and the year ends after week 52. Therefore, the weekyear() function will always return the same value as the week() function when the application uses broken weeks.

Diagram of weekyear() function's range

Diagram that shows the range of time that the weekyear() function evaluates. The weekyear() identifies the year that a week number took place in.

However, if the BrokenWeeks system variable is set to use unbroken weeks, week 1 must only contain a certain number of days in January based on the value specified in the ReferenceDay system variable.

For example, if a ReferenceDay value of 4 is used, week 1 must include at least four days in January. It is possible for week 1 to include dates in December of the previous year or for the final week number of a year to include dates in January of the following year. In situations like this, the weekyear() function will return a different value to the year() function.

Diagram of weekyear() function's range when using unbroken weeks

Diagram that shows how the weekyear() function works with unbroken weeks. If unbroken weeks are used, the weekyear() function will return a different value than the year() function.

The weekyear() function is useful when you would like to compare aggregations by years. For example, if you would like to see the total sales of products by year. The weekyear() function is chosen over year() when the user would like to retain consistency with the BrokenWeeks system variable in the app.

Regional settings

Unless otherwise specified, the examples in this topic use the following date format: MM/DD/YYYY. The date format is specified in the SET DateFormat statement in your data load script. The default date formatting may be different in your system, due to your regional settings and other factors. You can change the formats in the examples below to suit your requirements. Or you can change the formats in your load script to match these examples. For more information, see Modifying app regional settings.

Default regional settings in apps are based on a combination of identity provider settings, system settings, or browser settings. These regional format settings are not related to the language displayed in the Qlik Cloud user interface. Qlik Cloud will be displayed in the same language as the browser you are using.

If you are an app creator, you can set the default region for apps you create. For more information, see Setting your preferred regional settings for creating apps.

Function examples
Example Result
weekyear('12/30/1996') Returns 1997, because week 1 of 1997 starts on 12/30/1996
weekyear('01/02/1997') Returns 1997
weekyear('12/28/1997') Returns 1997
weekyear('12/30/1997') Returns 1998, because week 1 of 1998 starts on 12/29/1997
weekyear('01/02/1999') Returns 1998, because week 53 of 1998 ends on 01/03/1999
Related topics
Topic Interaction
week - script and chart function Returns an integer representing the week number according to ISO 8601
year - script and chart function Returns an integer representing the year when the expression is interpreted as a date according to the standard number interpretation.

Example 1 - Broken weeks

Example 2 - Unbroken weeks

Example 3 - Chart object example

Example 4 - Scenario