Skip to main content Skip to complementary content

year - script and chart function

This function returns an integer representing the year when the expression is interpreted as a date according to the standard number interpretation.



Return data type: integer

The year() function is available as both a script and chart function. The function returns the year for a particular date. It is commonly used to create a year field as a dimension in a Master Calendar.

When to use it

The year() function is useful when you would like to compare aggregations by year. For example, the function could be used if you would like to see the total sales of products by year.

These dimensions can be created either in the load script by using the function to create a field in a Master Calendar table. Alternatively, it could be used directly in a chart as a calculated dimension.

Function examples
Example Result
year( '2012-10-12' ) returns 2012
year( '35648' ) returns 1997, because 35648 = 1997-08-06

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.

Example 1 – DateFormat dataset (script)

Example 2 – ANSI Dates

Example 3 – Unformatted dates

Example 4 – Chart object example

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!