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. For more information, see Modifying regional settings for apps and scripts.
Default regional settings in apps are based on the user profile. 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.
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.
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.
Load script
The load script is a sequence of statements that defines what data to load and how to link the different loaded tables. It can be generated with the Data manager, or with the Data load editor, where it also can be viewed and edited.
Charts are objects where calculations, aggregations, and groupings can be made. Graphical visualizations, such as bar charts and pie charts are common examples, but also non-graphical objects such as pivot tables are charts.
A chart consists of dimensions and measures, where the measures are calculated once per dimensional value. If the chart contains multiple dimensions, the measures are calculated once per combination of dimensional values.
A Qlik Sense or QlikView app: Apps are task-specific, purpose-built applications. Apps contain data loaded from data sources that is interpreted through visualizations.
The Qlik Sense Mobile app: A mobile app for iOS and Android devices. In the mobile app, you connect to and interact with your cloud data. You can work with your available apps.
A measure is a calculation base on one ore more aggregations. For example, the sum of sales is a single aggregation, while the sum of sales divided by the count of customers is a measure based on two aggregations.
Sheets are components of Qlik Sense apps. They present visualizations to app users so they can explore, analyze, and discover data. Sheets can be public or private.
The term dataset is sometimes synonymous with table. It can refer to the original source table, the table after undergoing transformations, or the fact and dimension tables in a data mart.
It can also refer to a logical table, where there are several instance tables and views:
Current data
History, which holds previous versions of the table
A dimension is an entity used to categorize data in a chart. For example, the slices in a pie chart or the bars of a bar chart represent individual values in a dimension. Dimensions are often a single field with discrete values, but can also be calculated in an expression.
A dimension is a dataset in a data mart that forms part of the star schema. Dimension datasets hold the descriptive information for all related fields that are included in the fact table’s records. A few common examples of dimension datasets are Customer and Product. Since the data in a dimension dataset is often denormalized, dimension datasets have a large number of columns.