Skip to main content Skip to complementary content

weekyear - script and chart function

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


weekyear(timestamp [, first_week_day [, broken_weeks [, reference_day]]])

Return data type: integer

Argument Description
timestamp The date or timestamp to evaluate.

Specifies the day on which the week starts. If omitted, the value of variable FirstWeekDay is used.

The possible values first_week_day are 0 for Monday, 1 for Tuesday, 2 for Wednesday, 3 for Thursday, 4 for Friday, 5 for Saturday, and 6 for Sunday.

For more information about the system variable, see FirstWeekDay.


If you don't specify broken_weeks, the value of variable BrokenWeeks will be used to define if weeks are broken or not.

For more information about the system variable, see BrokenWeeks


If you don't specify reference_day, the value of variable ReferenceDay will be used to define which day in January to set as reference day to define week 1. By default, Qlik Sense functions use 4 as the reference day. This means that week 1 must contain January 4, or put differently, that week 1 must always have at least 4 days in January.

For more information about the system variable, see ReferenceDay

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

If BrokenWeeks is set to 0 (false), weekyear() will return the same as year().

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.

Default regional settings in apps are based on the regional system settings of the computer or server where Qlik Sense is installed. If the Qlik Sense server you are accessing is set to Sweden, the Data load editor will use Swedish regional settings for dates, time, and currency. These regional format settings are not related to the language displayed in the Qlik Sense user interface. Qlik Sense will be displayed in the same language as the browser you are using.

Function examples
Example Result
weekyear('12/30/1996',0,0,4) Returns 1997, because week 1 of 1997 starts on 12/30/1996
weekyear('01/02/1997',0,0,4) Returns 1997
weekyear('12/28/1997',0,0,4) Returns 1997
weekyear('12/30/1997',0,0,4) Returns 1998, because week 1 of 1998 starts on 12/29/1997
weekyear('01/02/1999',0,0,4) 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

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!