Working with dates
This section shows how you work with dates in your automation using the convert date function.
For the complete list of date functions, see date functions.
Convert a date to a timestamp
Working with integers is easier than working with dates because they have a defined data type and Unix timestamps have a defined format. Unix timestamps represent a data as the number of seconds since 1-1-1970. You can convert dates to Unix timestamps by applying a data function formula. For example, this automation shows how to convert a Qlik Sense app creation date to a Unix timestamp.
The Get App Information block returns information about a Qlik Sense app. The output block outputs the createdDate
key from the field mapped output of the preceding block. A formula is applied to the field mapping to covert the date to a time stamp. The 'U'
parameter in the formula specifies that the date value should be converted to a Unix timestamp.
The raw formula to convert the date looks like this:
{date:{$.GetAppInformation.info.attributes.createdDate},'U'}
Compare two dates
Using the example from the previous section, we can easily compare dates once they are converted to a Unix timestamp. For example, this automation uses a condition block to determine if the app was created recently or whether it was created more than five days ago.
The condition block converts the createdDate
to a Unix timestamp and adds the condition greater than 5 days ago
, as a Unix timestamp. Since the condition dates are both timestamps, they can easily be compared.
The raw formula to convert the second condition date looks like this:
{date:'now - 5 days','U'}
Calculate the difference between dates
Using the example from the first section, we can calculate the difference between two dates using a variable for the Unix timestamp. For example, this automation uses a variable to calculate the difference between the current date and the created date of the Qlik Sense app.
The variable block is set to the current date using a date formula to get the timestamp from now. This formula looks like this:
{date:'now','U'}
The variable has two more operations: one to substract the createdDate
, which is the same formula as in the previous examples, and another to divide the result by the number of second in a day, which is 86400. This must be done because Unix timestamps are expressed in seconds. Configure the output block to show the difference in days.