Skip to main content Skip to complementary content

weekname - script and chart function

This function returns a value showing the year and week number with an underlying numeric value corresponding to a timestamp of the first millisecond of the first day of the week containing date.


WeekName(date[, period_no [, first_week_day [, broken_weeks [, reference_day]]]])

The weekname() function determines which week the date falls into and returns the week number and year of that week. The first day of the week is determined by the FirstWeekDay system variable. However, you can also change the first day of the week by using the first_week_day argument in the weekname() function.

 In Qlik Sense, the regional settings are fetched when the app is created, and the corresponding settings are stored in the script as environment variables.

A North American app developer often gets Set BrokenWeeks=1; in the script, corresponding to broken weeks. A European app developer often gets Set BrokenWeeks=0; in the script, corresponding to unbroken weeks.

If your application uses broken weeks, the week number count begins on the January 1 and ends on the day prior to the FirstWeekDay system variable regardless of how many days have occurred.

However, if your application is using unbroken weeks, week 1 can begin in the previous year or in the first few days in January. This depends on how you use the ReferenceDay and FirstWeekDay system variables.

Example of Weekname function
Date ISO week name US week name
Sat 2020 Dec 26 2020/52 2020/52
Sun 2020 Dec 27 2020/52 2020/53
Mon 2020 Dec 28 2020/53 2020/53
Tue 2020 Dec 29 2020/53 2020/53
Wed 2020 Dec 30 2020/53 2020/53
Thu 2020 Dec 31 2020/53 2020/53
Fri 2021 Jan 1 2020/53 2021/01
Sat 2021 Jan 2 2020/53 2021/01
Sun 2021 Jan 3 2020/53 2021/02
Mon 2021 Jan 4 2021/01 2021/02
Tue 2021 Jan 5 2021/01 2021/02

The weekname() function is useful for when you would like to compare aggregations by weeks.

For example, if you want to see the total sales of products by week. To maintain consistency with the BrokenWeeks environment variable in the application, use weekname() instead of lunarweekname(). If the application is using unbroken weeks, week 1 may contain dates from December of the previous year or exclude dates in January of the current year. If the application is using broken weeks, week 1 may contain less than seven days.

Return data type: dual

Argument Description
timestamp The date or timestamp to evaluate.
period_no shift is an integer, where the value 0 indicates the week which contains date. Negative values in shift indicate preceding weeks and positive values indicate succeeding weeks.

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

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.

The examples below assume:

Set FirstWeekDay=0; Set BrokenWeeks=0; Set ReferenceDay=4;
Function examples
Example Result
weekname('01/12/2013') Returns 2013/02.
weekname('01/12/2013', -1) Returns 2013/01.
weekname('01/12/2013', 0, 1) Returns 2013/02.

Example 1 – Date with no additional arguments

Example 2 – period_no

Example 3 – first_week_day

Example 4 – Chart object example

Example 5 – 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!