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

Announcements
See why IDC MarketScape names Qlik a 2025 Leader! Read more
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Date Difference in Hours

Hi  Qlikers,

I need to know how to get the difference between two dates in hours but without counting weekends, example:

Date A: 01/12/2014 08:16:54.000

Date B: 28/11/2014 09:31:11.00

Real Difference: 71 hours

Expected Difference: 25 hours

Does anybody can help me??

Regards,

Carlos Martinez


1 Solution

Accepted Solutions
cwolf
Creator III
Creator III

Hi Carlos,

you can call the NetWorkDays function with defined holidays as additional parameters:

NetWorkDays(StartDate,EndDate,Holyday1,Holiday2,...)

In your example:

NetWorkDays(DateB,DateA,'25/12/2014')

Regards

Christian

View solution in original post

7 Replies
Anonymous
Not applicable
Author

Hi!

Something like this?

=

time(Interval([Date A]-DATE(lastWorkDate([Date B],2), 'DD/MM/YYYY hh:mm:ss[.fff]') ,'hh:mm')+
Interval((DATE(FirstWorkDate([Date A],2)&' 23:59:59' ,'DD/MM/YYYY hh:mm:ss[.fff]')-[Date B]),'hh:mm'),'hh')

From 09:31 of 28/11 to the end of day are 14,5 hours + from 00:00 of 01/12 to 08:16 are 8. I calculated 22 hours.

Let me know!

cwolf
Creator III
Creator III

Hi Carlos,

you can use the NetWorkDays Function:

(NetWorkDays(DateB,DateA)-2)*24 + 24-Hour(DateB) + Hour(DateA)

or for an exact calculation:

(NetWorkDays(DateB,DateA)-2)*24 + 24-Frac(DateB)*24 + Frac(DateA)*24

Regards

Christian

Not applicable
Author

Hi Elena,

Thanks for your reply but i put your formula on my chart and it doesn't display anything, maybe you have a mistake on it.

Regards


Not applicable
Author

Hi Christian,

Your answer Works thank you, but now i have another question, what i have to include in the formula you gave me to skip some defined days?

Example

Date A: 26/12/2014 09:02:17

Date B: 24/12/2014 11:28:16

With formula:

45.57 hours

Expected Result skipping 25/12/2014:

21 hours

Regards,

Carlos


cwolf
Creator III
Creator III

Hi Carlos,

you can call the NetWorkDays function with defined holidays as additional parameters:

NetWorkDays(StartDate,EndDate,Holyday1,Holiday2,...)

In your example:

NetWorkDays(DateB,DateA,'25/12/2014')

Regards

Christian

Not applicable
Author

Hi Christian,

Thanks for your reply it Works, but can NetWorkDays use instead Holiday1, Holiday2.... a variable with some days?

Regards

Carlos

consenit
Partner - Creator II
Partner - Creator II

Hi there.

Take a look at John Witherspoon reply on this thread, I used it once and worked like a charm:

http://community.qlik.com/message/94929#94929

Kind regards,

Ernesto.