Skip to main content Skip to complementary 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.


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

Argument Description
date The date or timestamp 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.

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.

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

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!