Skip to main content Skip to complementary content

weekday - script and chart function

This function returns a dual value with:

  • A day name as defined in the environment variable DayNames.
  • An integer between 0-6 corresponding to the nominal day of the week (0-6).

Syntax:  

weekday(date [,first_week_day=0])

Return data type: dual

The weekday() function determines which day of the week a date occurs on. It then returns a string value representing that day.

Diagram of weekday() function that returns the name of the day a date falls on

Diagram that shows the weekday() function returns the name of the day that a date falls on.

The result returns the number value corresponding to that day of the week (0-6), based on the week’s start day. For example, if the first day of the week is set to Sunday, a Wednesday will return a number value of 3. This start day is determined either by the FirstWeekDay system variable or the first_week_day function parameter.

You can use this number value as a part of an arithmetic expression. For example, multiply it by 1 to return the value itself.

Diagram of weekday() function with the number value of the day being shown instead of the name of the day

Diagram that shows the weekday() function can return a number value that corresponds to the day which is identified.

The weekday() function is useful when you want to compare aggregations by day of the week. For example, if you want to compare the average sales of products by weekday.

These dimensions can be created in the load script by using the function to create a field in a Master Calendar table; or created directly in a chart as a calculated measure.

Related topics
Topics Interaction
FirstWeekDay Defines the start day of each week.
Arguments
Argument Description
date The date or timestamp to evaluate.
first_week_day

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

FirstWeekDay

You can use the following values to set the day on which the week starts in the first_week_day argument:

first_week_day values
Day Value
Monday 0
Tuesday 1
Wednesday 2
Thursday 3
Friday 4
Saturday 5
Sunday 6

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.

Information noteUnless stated otherwise, FirstWeekDay is set to 0 in these examples.
Function examples
Example Result
weekday('10/12/1971') Returns 'Tue' and 1.
weekday('10/12/1971' , 6)

Returns 'Tue' and 2.

In this example, Sunday (6) is the first day of the week.

SET FirstWeekDay=6;

...

weekday('10/12/1971')

Returns 'Tue' and 2.

Example 1 - Weekday string

Example 2 - first_week_day

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!