Skip to main content

yearstart - script and chart function

This function returns a timestamp corresponding to the start of the first day of the year containing date. The default output format will be the DateFormat set in the script.

Syntax:  

YearStart(date[, period_no[, first_month_of_year]])

In other words, the yearstart() function determines which year the date falls into. It then returns a timestamp, in date format, for the first millisecond of that year. The first month of the year is, by default, January; however, you can change which month is set as first by using the first_month_of_year argument in the yearstart() function.

Diagram of yearstart() function that shows the range of time that the function can cover.

Diagram that shows the yearstart() function identifies dates within a given year period and returns the timestamp of the start of the year for dates that fall into that given year.

The yearstart() function is used as part of an expression when you want the calculation to use the fraction of the year that has elapsed thus far. For example, if you want to calculate the interest that has accumulated in a year to date.

Return data type: dual

Arguments
Argument Description
date The date to evaluate.
period_no period_no is an integer, where the value 0 indicates the year which contains date. Negative values in period_no indicate preceding years and positive values indicate succeeding years.
first_month_of_year If you want to work with (fiscal) years not starting in January, indicate a value between 2 and 12 in first_month_of_year.

The following months can be used in the first_month_of_year argument:

first_month_of_year values
Month Value
February  2
March 3
April 4
May 5
June 6
July 7
August 8
September 9
October 10
November  11
December 12

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.

Function examples
Example Result
yearstart('10/19/2001') Returns 01/01/2001 00:00:00.
yearstart('10/19/2001',-1) Returns 01/01/2000 00:00:00.
yearstart('10/19/2001',0,4) Returns 04/01/2001 00:00:00.

Example 1 – Basic example

Example 2 – period_no

Example 3 – first_month_of_year

Example 4 – Chart object example

Example 5 – Scenario