Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
hic
Former Employee
Former Employee

One Qlik function that occasionally causes confusion is the Date function. I have often seen errors caused by an incorrect usage of it, so today I will try to explain what the function does – and what it does not.

Interpretation vs Formatting

The first thing you should be aware of is that there are two different functions: Date#() and Date(). The first is an Interpretation function and the second is a Formatting function.

 

  • Interpretation functions use the textual value of the input, and convert this to a number.
  • Formatting functions use the numeric value of the input, and convert this to a text.

 

In both cases, the output is a dual, i.e. it has both a textual value and a numeric value. The textual value is displayed, whereas the numeric value is used for all numerical calculations and sorting.

 

The table below shows how to use the interpretation function Date#(). Note that the format code must match the input parameter.

 

Interpretation.png

 

This is very different from the formatting function Date(). Next table shows how to use this function. Note that the format code matches the format of the output text.

 

Formatting1.png

 

In real life, it is often useful to nest an interpretation function inside a formatting function:

 

Nested.png

 

Formatting vs Rounding

The second thing you should be aware of is that the Date() function and other formatting functions never change the numeric value of the input value.

 

This means that you can format a timestamp as a date only, without the time information. This can sometimes be confusing since there is a “hidden” value. In the table below, you can see that the input value corresponds to 12:00 in the middle of the day, but the Date() function effectively hides this from the textual output - but it remains in the the numeric value.

 

Formatting2.png

 

So what should you do if you want to remove the time part of the field, and just keep the date part? Well, obviously you must use a function that changes the numeric value: You need a Rounding function, e.g. DayStart() or Floor().

 

In the table below, you can compare the output of the Date() function with a couple of different rounding and formatting options.

 

Rounding.png

 

Summary

The above discussion is not relevant to dates only. It is just as relevant for Years, Weeks, hours, seconds and any other time interval. Further, it is relevant to a number of other functions:

 

Interpretation functions: Date#(), TimeStamp#(), Time#(), Interval#(), etc.

Formatting functions: Date(), TimeStamp(), Time(), Interval(), etc.

Rounding functions: Round(), Floor(), Ceil(), DayStart(), WeekStart(), MonthStart(), etc.

 

Combine these functions sensibly, and you will be able to round or format any way you want.

 

HIC

 

Further reading related to this topic:

Get the Dates Right

Why don’t my dates work?

39 Comments
Not applicable

Henric,

Nice Post..

Mohan

0 Likes
8,804 Views
robert99
Specialist III
Specialist III

Thanks Henric

Dates completely confused me when I first started using QV. I eventually found solutions but by trial and error. Now I finally understand (and I read all your previous blog posts on dates).

0 Likes
8,804 Views
dmohanty
Partner - Specialist
Partner - Specialist

A crystal clear blog. Very well explained!

0 Likes
8,847 Views
Not applicable

Thanks for the post ,

Regards,

Mahesh

0 Likes
8,847 Views
Not applicable

thank u

0 Likes
8,847 Views
Not applicable

How to Multiply Previous Rows in a Table

Hi, Could you help on this Problem? Thank you very much!

0 Likes
8,847 Views
Not applicable

1. "... , and convert this to a number.".

but

"...the output is a dual, i.e. it has both a textual value and a numeric value".

2. "..., and convert this to a text".

but

"...the output is a dual, i.e. it has both a textual value and a numeric value".

???

I can use it but I am not sure that I understand the layers here.

0 Likes
8,847 Views
hic
Former Employee
Former Employee

Both functions are duals, i.e. they both return a textual and a numeric value.

The textual input of the Date#() function will be used as textual output. In addition, the numeric interpretation of the text will be used as numeric value.

The numeric input of the Date() function will be used as numeric output. In addition, the textual formatting of the number will be used as textual value.

HIC

0 Likes
8,847 Views
Not applicable

thx, but there must like a "master and slave" concept in this. For instance what does the table viewer tag tells us, so for '#' the numric value becomes the "master"? Though still it is dual...   

0 Likes
8,871 Views
hic
Former Employee
Former Employee

You could say that for the Date#() function, the textual input is the master; and for the Date() function, the numeric input is the master.

Graphical explanation.png

In the Date#() function, the textual input is used (as-is) as output, and the numeric output is created (transformed) from the textual input. And the opposite is true for the Date() function.

HIC

8,871 Views