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

Date calculations

Hi there, 

need to substract date & time dimension to give me total time taken.
Dimension data is displayed: 

JoseGarcia_0-1633529281481.png

formula is:
axle1finish - axle1start

Using date & time function, but unable to get data in a way that allows me to perform any calculation.
Could anyone assist?
Thanks

Labels (1)
1 Solution

Accepted Solutions
stevejoyce
Specialist II
Specialist II

@mato32188 you have day before month so it's not matching syntax.

@JoseGarcia first convert field to be recognized as timestamp and then you can use interval.

 

convert to timestamp:

(timestamp#(left(right(axle1start,len(axle1start)-4),20),'MMM dd YYYY hh:mm:ss')) as axle1start,
(timestamp#(left(right(axle1finish ,len(axle1finish )-4),20),'MMM dd YYYY hh:mm:ss')) as axle1finish 

 

duration using interval:

interval(axle1finish - axle1start, 's') will show you difference in seconds

interval(axle1finish - axle1start, 'm:s') will show you difference in minutes:seconds

View solution in original post

10 Replies
mato32188
Specialist
Specialist

Hi @JoseGarcia ,

one of possible option is to play a bit with a string functions like:

load

(date#(left(right(start,len(start)-4),20),'DD MMM YYYY hh:mm:ss')) as start,
(date#(left(right(end,len(end)-4),20),'DD MMM YYYY hh:mm:ss')) as end

from xxx;

Then you can simply use expression sum(end-start) with result in days.

BR

m

 

ECG line chart is the most important visualization in your life.
stevejoyce
Specialist II
Specialist II

interval(axle1finish - axle1start, 's') will show you difference in seconds

interval(axle1finish - axle1start, 'm:s') will show you difference in minutes:seconds

JoseGarcia
Creator III
Creator III
Author

hi Mato32188, thanks for your suggestion. 

value is returning false.

JoseGarcia_0-1633613261234.png

 

JoseGarcia
Creator III
Creator III
Author

Steve, 
Thanks for your suggestion, value is returning false.

JoseGarcia_1-1633613384609.png

 

stevejoyce
Specialist II
Specialist II

Can you confirm your 2 fields are actually timestamp fields. Otherwise you will first need to use timestamp#(field, 'timestamp format of your text') to convert field type.

JoseGarcia
Creator III
Creator III
Author

Steve, 

my field data is displaying in this way:

Wed Oct 06 2021 14:27:09 GMT+0100 (BST)

Any ideas how could set the timestamp?

mato32188
Specialist
Specialist

Hi @JoseGarcia ,

load

(date#(left(right(axle1start,len(axle1start)-4),20),'MMM DD YYYY hh:mm:ss')) as axle1start,
(date#(left(right(axle1finish ,len(axle1finish )-4),20),'MMM DD YYYY hh:mm:ss')) as axle1finish 

FROM xxx;

BR

m

ECG line chart is the most important visualization in your life.
stevejoyce
Specialist II
Specialist II

@mato32188 you have day before month so it's not matching syntax.

@JoseGarcia first convert field to be recognized as timestamp and then you can use interval.

 

convert to timestamp:

(timestamp#(left(right(axle1start,len(axle1start)-4),20),'MMM dd YYYY hh:mm:ss')) as axle1start,
(timestamp#(left(right(axle1finish ,len(axle1finish )-4),20),'MMM dd YYYY hh:mm:ss')) as axle1finish 

 

duration using interval:

interval(axle1finish - axle1start, 's') will show you difference in seconds

interval(axle1finish - axle1start, 'm:s') will show you difference in minutes:seconds

mato32188
Specialist
Specialist

Yes. You are right.

@JoseGarcia ,

load

(date#(left(right(axle1start,len(axle1start)-4),20),'MMM DD YYYY hh:mm:ss')) as axle1start,
(date#(left(right(axle1finish ,len(axle1finish )-4),20),'MMM DD YYYY hh:mm:ss')) as axle1finish 

FROM xxx;

BR

m

ECG line chart is the most important visualization in your life.