Skip to main content Skip to complementary content

inweektodate - script and chart function

This function returns True if timestamp lies inside the part of week containing base_date up until and including the last millisecond of base_date.

Syntax:  

InWeekToDate (timestamp, base_date, period_no [, first_week_day])

Return data type: Boolean

Information note

In Qlik Sense, the Boolean true value is represented by -1, and the false value is represented by 0.

Diagram of inweektodate function

Example diagram of the range of date within which the inweektodate function will return a value of TRUE. In this case, it returns TRUE for certain days of the week, and FALSE for others.

The inweektodate() function uses the base_date parameter to identify a maximum boundary date of a week segment, as well as its corresponding date for the start of the week, which is based on the FirstWeekDay system variable (or user-defined first_week_day parameter). Once this week segment has been defined, the function will then return Boolean results when comparing the prescribed date values to that segment.

When to use it

The inweektodate() function returns a Boolean result. Typically, this type of function will be used as a condition in an if expression. This will return an aggregation or calculation dependent on whether a date evaluated occurred during the week in question up to and including a particular date.

For example, the inweektodate() function can be used to calculate all sales made during a specified week up to a particular date.

Arguments
Argument Description
timestamp The date that you want to compare with base_date.
base_date Date that is used to evaluate the week.
period_no The week can be offset by period_no. period_no is an integer, where the value 0 indicates the week which contains base_date. Negative values in period_no indicate preceding weeks and positive values indicate succeeding weeks.
first_week_day

By default, the first day of the week is Sunday (as determined by the FirstWeekDay system variable), starting at midnight between Saturday and Sunday. The first_week_day parameter supersedes the FirstWeekDay variable. To indicate the week starting on another day, specify a flag between 0 and 6.

For a week starting on Monday and ending on Sunday, use a flag of 0 for Monday, 1 for Tuesday, 2 for Wednesday, 3 for Thursday, 4 for Friday, 5 for Saturday, and 6 for Sunday.

 

Function examples
Example Interaction
inweektodate('01/12/2006', '01/12/2006', 0) Returns TRUE.
inweektodate('01/12/2006', '01/11/2006', 0) Returns FALSE.
inweektodate('01/12/2006', '01/18/2006', -1) Returns FALSE.
Because period_no is specified as -1, the effective data that timestamp is measured against is 01/11/2006.
inweektodate('01/11/2006', '01/12/2006', 0, 3 ) Returns FALSE, since first_week_day is specified as 3 (Thursday), which makes 01/12/2006 the first day of the week following the week containing 01/12/2006.

These topics may help you work with this function:

Related topics
Topic Default Flag / Value Description
FirstWeekDay 6 / Sunday Defines the start day of each week.

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.

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