This environment variable defines the date format used as the default in the app and by date returning functions like date() and date#(). The format is used to interpret and format dates. If the variable is not defined, the date format set by your regional settings is fetched when the script runs.
Syntax:
DateFormat
DateFormat Function examples
Example
Result
Set DateFormat='M/D/YY'; //(US format)
This use of the DateFormat function defines the date as the US format, month/day/year.
Set DateFormat='DD/MM/YY'; //(UK date format)
This use of the DateFormat function defines the date as the UK format, day/month/year.
Set DateFormat='YYYY/MM/DD'; //(ISO date format)
This use of the DateFormat function defines the date as the ISO format, year/month/day.
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 – System variables default
Overview
Open the Data load editor and add the load script below to a new tab.
The load script contains:
A dataset of dates.
The DateFormat function, which will use the US date format.
In this example, a dataset is loaded into a table named 'Transactions'. It includes a date field. The US DateFormat definition is used. This pattern will be used for implicit text to date conversion when the text dates are loaded.
Load script
Set DateFormat='MM/DD/YYYY';
Transactions:
LOAD
date,
month(date) as month,
id,
amount
INLINE
[
date,id,amount
01/01/2022,1,1000
02/01/2022,2,2123
03/01/2022,3,4124
04/01/2022,4,2431
];
Results
Load the data and open a sheet. Create a new table and add these fields as dimensions:
date
month
Create this measure:
=sum(amount)
Results table
date
month
=sum(amount)
01/01/2022
Jan
1000
02/01/2022
Feb
2123
03/01/2022
Mar
4124
04/01/2022
Apr
2431
The DateFormat definition MM/DD/YYYY is used for implicit conversion of text to dates, which is why the date field is properly interpreted as a date. The same format is used to display the date, as shown in the results table.
Example 2 – Change system variable
Overview
Open the Data load editor and add the load script below to a new tab.
The load script contains:
The same dataset from the previous example.
The DateFormat function, which will use the ‘DD/MM/YYYY’ format.
Load script
SET DateFormat='DD/MM/YYYY';
Transactions:
LOAD
date,
month(date) as month,
id,
amount
INLINE
[
date,id,amount
01/01/2022,1,1000
02/01/2022,2,2123
03/01/2022,3,4124
04/01/2022,4,2431
];
Results
Load the data and open a sheet. Create a new table and add these fields as dimensions:
date
month
Create this measure:
=sum(amount)
Results table
date
month
=sum(amount)
01/01/2022
Jan
1000
02/01/2022
Jan
2123
03/01/2022
Jan
4124
04/01/2022
Jan
2431
Because the DateFormat definition was set to ‘DD/MM/YYYY’, you can see that the two digits after the first “/” symbol have been interpreted as the month, resulting in all records being from the month of January.
Example 3 – Date interpretation
Overview
Open the Data load editor and add the load script below to a new tab.
The load script contains:
A dataset with dates in numerical format.
The DateFormat variable, which will use the ‘DD/MM/YYYY’ format.
The date() variable.
Load script
SET DateFormat='MM/DD/YYYY';
Transactions:
Load
date(numerical_date),
month(date(numerical_date)) as month,
id,
amount
Inline
[
numerical_date,id,amount
43254,1,1000
43255,2,2123
43256,3,4124
43258,4,2431
];
Results
Load the data and open a sheet. Create a new table and add these fields as dimensions:
date
month
Create this measure:
=sum(amount)
Results table
date
month
=sum(amount)
06/03/2022
Jun
1000
06/04/2022
Jun
2123
06/05/2022
Jun
4124
06/07/2022
Jun
2431
In the load script, you use the date() function to convert the numerical date into a date format. Because you do not provide a specified format as a second argument in the function, the DateFormat is used. This results in the date field using the format ‘MM/DD/YYYY’.
Example 4 – Foreign date formatting
Overview
Open the Data load editor and add the load script below to a new tab.
The load script contains:
A dataset of dates.
The DateFormat variable, which uses the ‘DD/MM/YYYY' format but is uncommented by forward slashes.
Load script
// SET DateFormat='DD/MM/YYYY';
Transactions:
Load
date,
month(date) as month,
id,
amount
Inline
[
date,id,amount
22-05-2022,1,1000
23-05-2022,2,2123
24-05-2022,3,4124
25-05-2022,4,2431
];
Results
Load the data and open a sheet. Create a new table and add these fields as dimensions:
date
month
Create this measure:
=sum(amount)
Results table
date
month
=sum(amount)
22-05-2022
-
1000
23-05-2022
-
2123
24-05-2022
-
4124
25-05-2022
-
2431
In the initial load script, the DateFormat being used is the default ‘MM/DD/YYYY’. Because the date field in the transactions dataset is not in this format, the field is not interpreted as a date. This is shown in the results table where the month field values are null.
You can verify the interpreted data types in the Data model viewer by inspecting the date field’s “Tags” properties.
This can be solved by enabling the DateFormat system variable:
// SET DateFormat='DD/MM/YYYY';
Remove the double forward slashes and reload the data.
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!