This function returns an integer representing the second when the fraction
of the expression is interpreted as a time
according to the standard number interpretation.
Syntax:
second (expression)
Return data type: integer
When to use it
The second() function is useful when you would like to compare aggregations by second. For example, the function can be used if you would like to see activity count distribution by second.
These dimensions can be created either in the load script by using the function to create a field in a Master Calendar table, or used directly in a chart as a calculated dimension.
Function examples
Example
Result
second(
'09:14:36' )
returns 36
second(
'0.5555' )
returns 55 ( Because 0.5555 = 13:19:55 )
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 – Variable
Overview
Open the Data load editor and add the load script below to a new tab.
The load script contains:
A dataset containing transactions by timestamp, which is loaded into a table called Transactions.
The default TimeStamp system variable (M/D/YYYY h:mm:ss[.fff] TT) is used.
The creation of a field, second, to calculate when purchases took place.
Load the data and open a sheet. Create a new table and add these fields as dimensions:
date
second
Results table
date
second
01/01/2022 10:10:22 PM
22
01/02/2022 8:35:54 AM
54
01/03/2022 5:40:49 AM
49
01/03/2022 2:21:53 PM
53
01/04/2022 6:49:38 PM
38
01/05/2022 7:04:57 PM
57
01/05/2022 7:34:46 PM
46
01/06/2022 8:49:09 AM
9
01/06/2022 11:29:38 AM
38
01/06/2022 10:58:34 PM
34
The values in the second field are created by using the second() function and passing the date as the expression in the preceding load statement.
Example 2 – Chart object
Overview
Open the Data load editor and add the load script below to a new tab.
The load script contains the same dataset and scenario as the first example. However, in this example, the unchanged dataset is loaded into the application. The second values are calculated via a measure in a chart object.
Load the data and open a sheet. Create a new table and add this field as a dimension:date.
Create the following measure:
=second(date)
Results table
date
=second(date)
01/01/2022 10:10:22 PM
22
01/02/2022 8:35:54 AM
54
01/03/2022 5:40:49 AM
49
01/03/2022 2:21:53 PM
53
01/04/2022 6:49:38 PM
38
01/05/2022 7:04:57 PM
57
01/05/2022 7:34:46 PM
46
01/06/2022 8:49:09 AM
9
01/06/2022 11:29:38 AM
38
01/06/2022 10:58:34 PM
34
The values for second are created by using the second() function and passing the date as the expression in a measure for the chart object.
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 of timestamps, which is generated to represent the traffic to a particular festival's ticket sales website. These timestamps and a corresponding id are loaded into a table called Web_Traffic.
The TimeStamp system variable M/D/YYYY h:mm:ss[.fff] TT is used.
In this scenario, there were 10000 tickets, which went on sale at 9:00 AM on May 20, 2021. One minute later, the tickets were sold out.
The user would like a chart object that shows, by second, the count of visits to the website.
Load script
SET TimestampFormat='M/D/YYYY h:mm:ss[.fff] TT';
tmpTimeStampCreator:
load
makedate(2022,05,20) as date
AutoGenerate 1;
join load
maketime(9+floor(rand()*2),0,floor(rand()*59)) as time
autogenerate 10000;
Web_Traffic:
load
recno() as id,
timestamp(date + time) as timestamp
resident tmpTimeStampCreator;
drop table tmpTimeStampCreator;
Results
Do the following:
Load the data and open a sheet. Create a new table.
Next, create a calculated dimensions using the following expression:
=second(timestamp)
Create an aggregation measure to calculate the total count of entries:
=count(id)
The results table will look similar to the table below, but with different values for the aggregation measure:
Results table
second(timestamp)
=count(id)
0
150
1
184
2
163
3
178
4
179
5
158
6
177
7
169
8
149
9
186
10
169
11
179
12
186
13
182
14
180
15
153
16
191
17
203
18
158
19
159
20
163
+ 39 more rows
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!