Skip to main content

weekstart - script and chart function

This function returns a value corresponding to a timestamp of the first millisecond of the first day (Monday) of the calendar week containing date. The default output format is the DateFormat set in the script.

Syntax:  

WeekStart(date [, period_no[, first_week_day]])

Return data type: dual

Diagram of weekstart() function

Example diagram showing how the weekstart function converts an input date into a timestamp for the first millisecond of the week in which the date occurs.

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

Arguments
Argument Description
date The date 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 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 weekstart() function is commonly used as part of an expression when the user would like the calculation to use the fraction of the week that has elapsed thus far. For example, it could be used if a user would like to calculate the total wages earned by employees in the week so far.

Function examples
Example Result
weekstart('01/12/2013') Returns 01/07/2013.
weekstart('01/12/2013', -1 ) Returns 11/31/2012.
weekstart('01/12/2013', 0, 1) Returns 01/08/2013.

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.

Example 1 – No additional arguments

Example 2 – period_no

Example 3 – first_week_day

Example 4 – Chart object example

Example 5 – Scenario