This function returns a timestamp of the current
time. The function returns values in the TimeStamp system variable format. The default timer_mode value is 1.
Syntax:
now([
timer_mode])
Return data type: dual
The now() function can be used either in the load script or in chart objects.
Arguments
Argument
Description
timer_mode
Can have the following values:
0 (time
at last finished data load) 1 (time at function call) 2 (time when the app was opened)
Information noteIf you use the function in a data load script, timer_mode=0 will result in the time of the last finished data load, while timer_mode=1 will give the time of the function call in the current data load.
Tip noteThe now() function has a high-performance impact, which might result in scrolling issues if the function is used within tables' expressions. Whenever its use is not strictly necessary, we recommend using the today() function instead. If the use of now() is required in a layout, we recommend using the non-default settings now(0) or now(2) when possible, as they do not require constant recalculations
When to use it
The now() function is commonly used as a component within an expression. For example, it can be used to calculate the time remaining in a product's lifecycle. The now() function would be used instead of the today() function when the expression requires the use of a fraction of a day.
The following table provides an explanation of the result returned by the now() function, given different values for the timer_mode argument:
Function examples
timer_mode value
Result if used in load script
Result if used in chart object
0
Returns a timestamp, in the TimeStamp system variable format, of the last successful data reload prior to the latest data reload.
Returns a timestamp, in the TimeStamp system variable format, for the latest data reload.
1
Returns a timestamp, in the TimeStamp system variable format, for the latest data reload.
Returns a timestamp, in the TimeStamp system variable format, of the function call.
2
Returns a timestamp, in the TimeStamp 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 timestamp, in the TimeStamp 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.
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
Open the Data load editor and add the load script below to a new tab.
This example creates three variables using the now() 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 a short period of time, reload the script a second time. This will result in the now(0) and now(1) variables showing different values, thereby correctly demonstrating their purpose.
Load script
LET vPreviousDataLoad = now(0);
LET vCurrentDataLoad = now(1);
LET vApplicationOpened = now(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: 6/22/2022 8:54:03 AM
Current Reload Time: 6/22/2022 9:02:08 AM
User Session Began: 6/22/2022 8:40:40 AM
Example 2 – Generation of objects without load script
Overview
In this example, you will create three chart objects using the now() function, without loading any variables or data into the application. Each chart object uses one of the timer_mode options to demonstrate their effect.
There is no load script for this example.
Do the following:
Open the Data load editor.
Without changing the existing load script, click Load data.
After a short period of time, load the script a second time.
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:
=now(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:
=now(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: 6/22/2022 9:02:08 AM
Current Time: 6/22/2022 9:25:16 AM
User Session Began: 6/22/2022 8:40:40 AM
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 consisting of inventory for a cryptocurrency mining operation, which is loaded into a table called Inventory.
Data with the following fields: id, purchase_date, and wph (watts per hour).
The user would like a table that displays, by id, the total cost each mining rig has incurred in the month so far, in terms of power consumption.
This value should update whenever the chart object is refreshed. The current cost of electricity is $0.0678 per kWH.
Load the data and open a sheet. Create a new table and add this field as a dimension: id.
Create the following measure:
=(now(1)-monthstart(now(1)))*24*wph/1000*0.0678
If the chart object was refreshed at 6/22/2022 10:39:05 AM, it would return the following results:
Results table
id
=(now(1)-monthstart(now(1)))*24*wph/1000*0.0678
8188
$39.18
8189
$49.97
8190
$42.81
8191
$46.13
8192
$44.42
8193
$39.18
8194
$46.83
8195
$81.72
8196
$42.95
8197
$42.95
8198
$39.18
8199
$42.29
8200
$42.67
8201
$42.99
8202
$42.99
8203
$42.25
8204
$43.37
8205
$46.13
8206
$39.53
The user would like the object results to refresh every time the object is refreshed. Therefore, the timer_mode argument of supplied for instances of the now() function in the expression. The timestamp for the start of the month, identified by using the now() function as the timestamp argument in the monthstart() function, is subtracted from the current time which is identified by the now() function. This provides the total amount of time that has elapsed so far this month, in days.
This value is multiplied by 24 (the number of hours in a day) and then by the value in the wphfield.
To convert from watts per hour to kilowatts per hour, the result is divided by 1000 before finally being multiplied by the kWH rate supplied.
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 field contains values, loaded from a data source. At a basic level, a field corresponds to a column in a table. Fields are used to create dimensions and measures in visualizations.