This function returns the current date. The function returns values in the DateFormat system variable format.
Syntax:
today([
timer_mode])
Return data type: dual
The today() function can be used either in the load script or in chart objects.
The default timer_mode value is 1.
Arguments
Argument
Description
timer_mode
Can have the following values:
0 (day of last finished data load) 1 (day of function call) 2 (day when the app was opened)
Information noteIf you use the function in a load script, timer_mode=0 will result in the day of the last finished data load, while timer_mode=1 will give the day of the current data load.
Function examples
timer_mode value
Result if used in load script
Result if used in chart object
0
Returns a date, in the DateFormat system variable format, of the last successful data reload prior to the latest data reload.
Returns a date, in the DateFormat system variable format, for the latest data reload.
1
Returns a date, in the DateFormat system variable format, for the latest data reload.
Returns a date, in the DateFormat system variable format, of the function call.
2
Returns a date, in the DateFormat system variable format, for when the user’s session in the application began. This will not be updated unless the user reloads the script.
Returns the date, in the DateFormat system variable format, for when the user’s session in the application began. This will be refreshed once a new session begins or the data in the application is reloaded.
When to use it
The today() function is commonly used as a component within an expression. For example, it can be used to calculate the interest that has accumulated in a month up to the current date.
The following table provides an explanation of the result returned by the today() function, given different values for the timer_mode argument:
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 – Generation of objects using load script
Overview
The following example creates three variables using the today() function. Each variable uses one of the timer_mode options to demonstrate their effect.
For the variables to demonstrate their purpose, reload the script and then, after 24 hours, reload the script a second time. This will result in the today(0) and today(1) variables showing different values, thereby correctly demonstrating their purpose.
Load script
LET vPreviousDataLoad = today(0);
LET vCurrentDataLoad = today(1);
LET vApplicationOpened = today(2);
Results
Once the data has been loaded for a second time, create three textboxes using the directions below.
First, create a textbox for the data which has previously been loaded.
Do the following:
Using the Text & Image chart object, create a textbox.
Add the following measure to the object:
=vPreviousDataLoad
Under Appearance, select Show titles and add the title 'Previous Reload Time' to the object.
Next, create a textbox for the data which is currently being loaded.
Do the following:
Using the Text & Image chart object, create a textbox.
Add the following measure to the object:
=vCurrentDataLoad
Under Appearance, select Show titles and add the title 'Current Reload Time' to the object.
Create a final textbox to show when the user's session in the application was started.
Do the following:
Using the Text & Image chart object, create a textbox.
Add the following measure to the object:
=vApplicationOpened
Under Appearance, select Show titles and add the title 'User Session Started' to the object.
The above image shows example values for each of the created variables. For example, the values could be as follows:
Previous Reload Time: 06/22/2022
Current Reload Time: 06/23/2022
User Session Began: 06/23/2022
Example 2 – Generation of objects without load script
Overview
The following example creates three chart objects using the today() function. Each chart object uses one of the timer_mode options to demonstrate their effect.
There is no load script for this example.
Results
Once the data has been loaded for a second time, create three textboxes.
First, create a textbox for the latest data reload.
Do the following:
Using the Text & Image chart object, create a textbox.
Add the following measure:
=today(0)
Under Appearance, select Show titles and add the title 'Latest Data Reload' to the object.
Next, create a textbox to show the current time.
Do the following:
Using the Text & Image chart object, create a textbox.
Add the following measure:
=today(1)
Under Appearance, select Show titles and add the title 'Current Time' to the object.
Create a final textbox to show when the user's session in the application was started.
Do the following:
Using the Text & Image chart object, create a textbox.
Add the following measure:
=today(2)
Under Appearance, select Show titles and add the title 'User Session Began' to the object.
The above image shows example values for each of the created objects. For example, the values could be as follows:
Latest Data Reload: 06/23/2022
Current Time: 06/23/2022
User Session Began: 06/23/2022
The 'Latest Data Reload' chart object uses a timer_mode value of 0. This returns the timestamp for the last time the data was successfully reloaded.
The 'Current Time' chart object uses a timer_mode value of 1. This returns the current time according to the system clock. If the sheet or object is refreshed, this value will be updated.
The 'User Session Began' chart object uses a timer_mode value of 2. This returns the timestamp for when the application was opened, and the user’s session began.
Example 3 – Scenario
Overview
Open the Data load editor and add the load script below to a new tab.
The load script contains:
A dataset containing a set of loan balances, which is loaded into a table called Loans.
Table data with fields for loan ID, balance at the start of the month, and the simple interest rate charged on each loan per annum.
The end user would like a chart object that displays, by loan ID, the current interest that has been accrued on each loan in the month to date. Although the application is only reloaded once per week, the user would like the results to be refreshed whenever the object or application is refreshed.
The monthstart() function, using the today() function to return today’s date as its only argument, returns the start date of the current month. By subtracting that result from the current date, again using the today() function, the expression returns the number of days that have elapsed so far this month.
This value is then multiplied by the interest rate and divided by 365 to return the effective interest rate incurred for this period. The result is then multiplied by the starting balance of the loan to return the interest that has been accrued so far this month.
Because the value of 1 is used as the timer_mode argument in the today() functions inside the expression, each time the chart object is refreshed (by opening the application, refreshing the page, moving between sheets, etc.), the date returned will be for the current date, and the results will be refreshed accordingly.
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!