Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Determing number of hours between two dates

I have two fields: "start_time" and "end_time"

Format of data in both fields is: "2009-07-21 16:00:00.000". The start and end times for each record are always on the same date/day.

I added the following code to subtract the start time from the end time : "end_time - start_time as duration"

It works, but the it puts the result in date/time format instead of numeric. For example, if the duration for a record that occurs on 7/21/2009 is 3 hours, it shows it as "2009-07-21 3:00:00.000" instead of "3".

I'm a VERY basic developer. Any suggestions on how to simply accomplish this??

12 Replies
hector
Specialist
Specialist

Hi, that sintax is wrong, why are you using 3 parameters? interval only has 2.

change your sintax to

<pre>Interval('03/30/2009 14:29:26' - '03/30/2009 14:29:10','hh:mm:ss')
Interval('09/16/2009 19:00:27' - '09/16/2009 19:00:14','hh:mm:ss')



and be careful with the format of TimestampFormat variable, it mus be equal to your dates format.

and about to group the '00', maybe the value showed is '00', and internally has another value, in this case 16 and 13 seconds (check the decimal part)

rgds

amit_shetty78
Creator II
Creator II

Thanks Hector.

Apologies there. It was a typo earlier. Should have been '-' instead of ',' in the Interval function.

Changed the script to

Interval(End_Date - Start_Date,'hh') & ''


this works and now the list box has just one row for 00.

Rgds.

Not applicable
Author

Hi,

Try this:

This gives the time between two dates as a fraction of days... That is if the value of age is 1.07 after calculation, it means 1 day and .07 fraction of the 2nd day.

if(end_time=' ',num#((Interval#(now()-start_time))),num#((Interval#(end_time-start_time)))) as Age

In this expression if the end time is not given then the age is calculated as now()-start_time where now() gives the present time.