Skip to main content
Announcements
Customer Spotlight: Discover what’s possible with embedded analytics Oct. 16 at 10:00 AM ET: REGISTER NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Calculating Time between time stamps


I've been trying to modify this statement in this post:

http://community.qlik.com/thread/79893

I'm dealing with pure time stamps, no dates, and I need to calculate the time between multiple time stamps.

I read somewhere there is a problem with using MM for minutes.

Can I modify this or other statements to calculate time:

=Ceil(Interval(Date#([Field2], 'MM/DD/YYYY hh:mm:ss TTT') - Date#([Field1], 'MM/DD/YYYY hh:mm:ss TTT'), 'DD' ))

or are there other options?

Thank you for your help!

1 Solution

Accepted Solutions
Not applicable
Author

Please find the attached qvw for reference.

SAMPLE:

LOAD * ,  Num(DIFF_IN_SEC/3600,'#####0.00') AS Hours_Diff;

LOAD * ,

  Num#(Text(Interval(ResultTS-ReciveTS , 's'))) AS DIFF_IN_SEC

  ;

LOAD BatTstCode,

    RecDateODBC,

    ReceiveTimeODBC,

    Timestamp#(RecDateODBC & ' ' & ReceiveTimeODBC , 'DD-MMM-YYYY mm:hh:ss') AS ReciveTS ,

    ResultDateODBC,

    ResultTimeODBC,

    Timestamp#(ResultDateODBC & ' ' & ResultTimeODBC , 'DD-MMM-YYYY mm:hh:ss') AS ResultTS

FROM timestamp.txt (txt, codepage is 1252, embedded labels, delimiter is '\t', msq);

View solution in original post

22 Replies
jpapador
Partner - Specialist
Partner - Specialist

Have you tried, Num(Field2) - Num(Field1).  That will give you the difference in days.  You can multiply by 60 once or twice to get it into hours or minutes. 

Not applicable
Author

Thank you, I will try that.  Looking for time in minutes.

I do get negative numbers when the time crosses a calendar date.  Thoughts?

Anonymous
Not applicable
Author

Rebecca

MM is for a 2 digit month.

mm is for minutes.

Interval() is a good function to use, as per this example.

Interval (

  date#( '12/26/2013 12:12:12' , 'MM/DD/YYYY hh:mm:ss')

  -

  date#( '12/25/2013 22:22:22' , 'MM/DD/YYYY hh:mm:ss')

, 'mm' )



Best Regards,     Bill

Not applicable
Author

Thank you Bill.

I am working with pure timestamps, so I am now modifying my load statement to create DTS:

Hopefully then I can try your suggestion.


Not applicable
Author


I added the following to my load statement to my load statement to obtain DTS.

 

(Timestamp#(ReceiveDateODBC & ' '& ReceiveTimeODBC,'DD/MM/YYYY hh:mm:ss'),'DD/MM/YYY hh:mm:ss') as ReceiveDTS,

The results are as follows:

BatTstCodeRecDateODBCReceiveTimeODBCReceivedDTSResultDateODBCResultTimeODBCResultDTS
ADMIN22-Nov-1316:26:0041600 0.684722222222226-Dec-1315:43:0041614 0.65486111111111
ADMIN22-Nov-1316:26:0041600 0.6847222222222222-Nov-1316:27:0041600 0.68541666666667
UCUL22-Nov-1316:26:0041600 0.6847222222222223-Nov-138:40:0041601 0.36111111111111
UCUL22-Nov-1316:26:0041600 0.6847222222222224-Nov-1310:14:0041602 0.42638888888889

Any pointers?

Anonymous
Not applicable
Author

Rebecca

Try this :

TimeStamp ( Timestamp#(ReceiveDateODBC & ' '& ReceiveTimeODBC,'DD/MM/YYYY hh:mm:ss'),'DD/MM/YYYY hh:mm:ss')  as ReceiveDTS,

Best Regards,,    Bill

Not applicable
Author

Thank you Bill for all your help.  The output is still not usable for calculating the time between events.  If I could work strictly from time, there would be no issue, but the crossing of calendar day gives me bad results.

Any other pointers?

Not applicable
Author

Generally we can use the Interval function to calculate the difference b/n time stamps. But the actual format of Interval function is time format. For example if you want calculate the difference the time in Hours, first calculate in Seconds and then convert this seconds into Number. Once we get the difference in Seconds we can convert into any hours, days or Minutes.

Num#(Text(Intervale(Timestamp1 - Timestamp2 , 's'))) AS DIFF_IN_SEC

Not applicable
Author


Thank you for your response.

I have tried the interval function, but will try this syntax as well. Unfortunately, my time stamps can cross days so I'm getting inaccurate results.....