Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
shakeeb_mohammed
Contributor III
Contributor III

Timestamp function

Hi,

Could someone help me with the following script please -

if(Timestamp([Confirmed Arrival Time])>Timestamp([PTA]),1,0) as LatePTA,

     if(Timestamp([Confirmed Arrival Time])<Timestamp([PTA]),1,0) as OnTimePTA,

I'm trying to add a statement that will say if the confirmed arrival time is more or less than 30 minutes of the PTA mark it as OnTimePTA

I am using Qliksense - Thanks in advance!

10 Replies
ToniKautto
Employee
Employee

Great to hear that you found the formula you where looking for!

I would recommend reviewing the expression, since I think you have introduced a few unnecessary formatting steps in your example. Something like this should give the same result;

if(interval([Confirmed Arrival Time] - [PTA]) <= 30/(60*24),1,0) as OnTimePTA

if(interval([Confirmed Arrival Time] - [PTA]) > 30/(60*24),1,0) as LatePTA

---

For calculations and comparisons all processing is done on the underlying numerical value of your data point. This means that all values are treated as Dual values, with a visual text part and an underlying numerical value.

The formatting Timestamp([Confirmed Arrival Time],'hh:mm:ss') will actually only change the way the timestamp is presented, the underlying numerical value will still contain the exact date and time. IF you wanted to convert the timestamp to a time the proper syntax would be Time(Frac([Confirmed Arrival Time])), so that the integer representing the date is removed by only keeping the fraction of the underlying numerical value.

Interval() calculates the time between to point in time, which means it will aggregate the difference of the numerical value of our timestamp. There is no need to reformat that timestamp prior to this operation.

if(num#(interval([Confirmed Arrival Time] - [PTA],'m')) <= 30,1,0) as OnTimePTA

if(num#(interval([Confirmed Arrival Time] - [PTA],'m')) > 30,1,0) as LatePTA

As I mentioned above time is a fraction, which also applies for the result of Interval (). The result will be a fraction representing the interval. The format to minute in above example, again only changes the visual value and does not alter the underlying fraction.

30 minutes of a 24 hour day with 60 minutes per hour can be represented as the fraction 30 / (60 * 24). Instead of forcing your interval into an integer you can simply compare with the 30 minute fraction. Which leads you to the optimized expressions;

if(interval([Confirmed Arrival Time] - [PTA]) <= 30/(60*24),1,0) as OnTimePTA

if(interval([Confirmed Arrival Time] - [PTA]) > 30/(60*24),1,0) as LatePTA