This function returns a time calculated from the hour hh, the minute mm, and the second ss.
Syntax:
MakeTime(hh [ , mm [ , ss ] ])
Return data type: dual
Arguments
Argument
Description
hh
The hour as an integer.
mm
The minute as an integer.
If no minute is stated, 00 is assumed.
ss
The second as an integer.
If no second is stated, 00 is assumed.
When to use it
The maketime() function would commonly be used in the script for data generation to generate a time field. Sometimes, when the time field is derived from input text, this function could be used to construct the time using its components.
These examples use the time format h:mm:ss. The time format is specified in the SET TimeFormatstatement at the top of your data load script Change the format in the examples to suit your requirements.
Function examples
Example
Result
maketime(22)
Returns 22:00:00.
maketime(22, 17)
Returns 22:17:00.
maketime(22,17,52 )
Returns 22:17:52.
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.
Load the data and open a sheet. Create a new table and add these fields as dimensions:
transaction_hour
transaction_minute
transaction_second
transaction_time
Results table
transaction_hour
transaction_minute
transaction_second
transaction_time
2
52
22
2:52:22 AM
6
32
07
6:32:07 AM
9
25
23
9:25:23 AM
12
09
16
12:09:16 PM
17
55
22
5:55:22 PM
18
43
30
6:43:30 PM
21
43
41
9:43:41 PM
The transaction_time field is created in the preceding load statement by using the maketime() function, and passing the hour, minute, and second fields as function arguments.
The function then combines and converts these values into a time field, returning the results in the time format of the TimeFormat system variable.
Example 2 – time() function
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.
The creation of a field, transaction_time, which will allow us to show the results in 24-hour time format without modifying the TimeFormat system variable.
Load the data and open a sheet. Create a new table and add these fields as dimensions:
transaction_hour
transaction_minute
transaction_second
transaction_time
Results table
transaction_hour
transaction_minute
transaction_second
transaction_time
2
52
22
2:52:22
6
32
07
6:32:07
9
25
23
9:25:23
12
09
16
12:09:16
17
55
22
17:55:22
18
43
30
18:43:30
21
43
41
21:43:41
In this instance, the maketime() function is nested inside the time() function. The second argument of the time() function sets the format of the maketime() function results as the required h:mm:ss.
Example 3 – Chart object example
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 transactions , which is loaded into a table called Transactions.
Transaction times provided across two fields: hours and minutes.
The creation of a field, transaction_time, that returns the time in the format of the TimeFormat system variable.
Create a chart object measuretransaction_time, that returns a time in the format h:mm:ss TT.
Load the data and open a sheet. Create a new table and add these fields as dimensions:
transaction_hour
transaction_minute
To calculate the transaction_time, create this measure:
=maketime(transaction_hour,transaction_minute)
Results table
transaction_hour
transaction_minute
=maketime(transaction_hour, transaction_minute)
2
52
2:52:00 AM
6
32
6:32:00 AM
9
25
9:25:00 AM
12
09
12:09:00 PM
17
55
5:55:00 PM
18
43
6:43:00 PM
21
43
9:43:00 PM
The transaction_time measure is created in the chart object by using the maketime() function, and passing the hour and minute fields as function arguments.
The function then combines these values, and seconds are assumed to be 00. These values are then converted into a time field, returning the results in the format of the TimeFormat system variable.
Example 4 – Scenario
Overview
Create a calendar dataset for the month of January 2022, broken out into eight-hour increments.
Load script
SET TimestampFormat='M/D/YYYY h:mm:ss[.fff] TT';
tmpCalendar:
load
*
where year(date)=2022;
load
date(recno()+makedate(2021,12,31)) as date
AutoGenerate 31;
Left join(tmpCalendar)
load
maketime((recno()-1)*8,00,00) as time
autogenerate 3;
Calendar:
load
timestamp(date + time) as timestamp
resident tmpCalendar;
drop table tmpCalendar;
Results
Results table
timestamp
1/1/2022 12:00:00 AM
1/1/2022 8:00:00 AM
1/1/2022 4:00:00 PM
1/2/2022 12:00:00 AM
1/2/2022 8:00:00 AM
1/2/2022 4:00:00 PM
1/3/2022 12:00:00 AM
1/3/2022 8:00:00 AM
1/3/2022 4:00:00 PM
1/4/2022 12:00:00 AM
1/4/2022 8:00:00 AM
1/4/2022 4:00:00 PM
1/5/2022 12:00:00 AM
1/5/2022 8:00:00 AM
1/5/2022 4:00:00 PM
1/6/2022 12:00:00 AM
1/6/2022 8:00:00 AM
1/6/2022 4:00:00 PM
1/7/2022 12:00:00 AM
1/7/2022 8:00:00 AM
1/7/2022 4:00:00 PM
1/8/2022 12:00:00 AM
1/8/2022 8:00:00 AM
1/8/2022 4:00:00 PM
1/9/2022 12:00:00 AM
+ 68 more rows
The initial autogenerate function creates a calendar containing all the dates in January in a table called tmpCalendar.
A second table, containing three records, is created. For each record, recno() – 1 is taken (values 0, 1, 2) and the result is multiplied by 8. As a result, this generates the values 0, 8 16. These values are used as the hour parameter in a maketime() function, with minute and second values of 0. As a result, the table contains three time fields: 12:00:00 AM, 8:00:00 AM, and 4:00:00 PM.
This table is joined to the tmpCalendar table. Because there are no matching fields between the two tables for the join, the time rows are added to each date row. As a result, each date row is now repeated three times with each time value.
Finally, the Calendar table is created from a resident load of the tmpCalendar table. The date and time fields are concatenated and wrapped in the timestamp() function to create the timestamp field.
The tmpCalendar table is then dropped.
Field
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.
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.
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 preceding load is a script construct that allows you to load from the following LOAD or SELECT statement without specifying that source. Preceding loads are often faster than resident loads.
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.
A resident load is a script construct that allows you to load from an already loaded table. Resident loads are often faster than accessing the original data source again.