Skip to main content Skip to complementary content

weekend - script and chart function

This function returns a value corresponding to a timestamp of the last millisecond of the last day of the calendar week containing date. The default output format will be the DateFormat set in the script.

Syntax:  

WeekEnd(timestamp [, period_no [, first_week_day ]])

Return data type: dual

The weekend() function determines which week the date falls into. It then returns a timestamp, in date format, for the last millisecond of that week. The first day of the week is determined by the FirstWeekDay environment variable. However, this can be superseded by the first_week_day argument in the weekend() function.

Arguments
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.
first_week_day

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

The possible values for 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

When to use it

The weekend() function is commonly used as part of an expression when the user would like the calculation to use remaining days of the week for the specified date. For example, it could be used if a user would like to calculate the total interest not yet incurred during the week.

The following examples assume:

SET FirstWeekDay=0;

 

Example Result
weekend('01/10/2013') Returns 01/12/2013 23:59:59.
weekend('01/10/2013', -1) Returns 01/05/2013 23:59:59..
weekend('01/10/2013', 0, 1) Returns 01/14/2013 23:59:59.

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 regional settings for apps and scripts.

Default regional settings in apps are based on the user profile. 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 and scripts in Qlik Cloud Analytics.

Examples:  

If you want ISO settings for weeks and week numbers, make sure to have the following in the script:

Set DateFormat ='YYYY-MM-DD'; Set FirstWeekDay =0; // Monday as first week day Set BrokenWeeks =0; //(use unbroken weeks) Set ReferenceDay =4; // Jan 4th is always in week 1

If you want US settings, make sure to have the following in the script:

Set DateFormat ='M/D/YYYY'; Set FirstWeekDay =6; // Sunday as first week day Set BrokenWeeks =1; //(use broken weeks) Set ReferenceDay =1; // Jan 1st is always in week 1

The examples above results in the following from the weekend() function:

Example of Weekend function
Date ISO week end US week end
Sat 2020 Dec 26 2020-12-27 12/26/2020
Sun 2020 Dec 27 2020-12-27 1/2/2021
Mon 2020 Dec 28 2021-01-03 1/2/2021
Tue 2020 Dec 29 2021-01-03 1/2/2021
Wed 2020 Dec 30 2021-01-03 1/2/2021
Thu 2020 Dec 31 2021-01-03 1/2/2021
Fri 2021 Jan 1 2021-01-03 1/2/2021
Sat 2021 Jan 2 2021-01-03 1/2/2021
Sun 2021 Jan 3 2021-01-03 1/9/2021
Mon 2021 Jan 4 2021-01-10 1/9/2021
Tue 2021 Jan 5 2021-01-10 1/9/2021
Information noteThe week ends are on Sundays in the ISO column, and on Saturdays in the US column.

Example 1 – Basic example

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!