Skip to main content
Document boards are being consolidated, this board no longer allows NEW documents READ MORE

Working Hours Calculation excluding weekends and holidays

Showing results for 
Search instead for 
Did you mean: 

Working Hours Calculation excluding weekends and holidays


Working hours calculation is essential measure which is useful in many business cases.  In this post I am going to demonstrate the steps to calculate this measure.  I have also covered other aspects related to working hours like overtime hours and excluding lunch break hours.  

Example in this post works for weekends as Saturday and Sunday. If you have any other weekends then refer to my below post


Consider the below case

Let's say one Ticket is logged into the system on certain day , call it as Start Date, and the same Ticket got resolved on certain day, call it as End Day. Now we may want to calculate the working hours between these two Dates to calculate the efficiency of ticket closure time.

1) Calculate business working hours excluding week ends(Saturday and Sunday) and Holidays.

Below are the considerations

1) Count only standard working hours ( 9 AM - 6 PM)

2) Exclude Saturdays and Sundays

3) Exclude Holidays

Below is the Setup in QlikView

You can change the Date format of the below variables as per your convenience eg. 'DD/MM/YYYY hh:mm:ss' to 'DD-MMM-YYYY hh:mm:ss'

SET TimeFormat='hh:mm:ss';
SET DateFormat='DD/MM/YYYY';

SET TimestampFormat='DD/MM/YYYY hh:mm:ss';

First, convert your Timestamp date format to 24 hour format using the below functions

a) Timestamp# ()    (if your Timestamp values are text) 

b) TimeStamp ()     (If your Timestamp values are in proper Timestamp format)

Now you can setup the below variables for standard working hours in weekdays.You can change the Variable according to your working hours (Here 9 AM - 6 PM) and rest calculation will be done automatically

Now Setup the Holiday list as below. You can use your own holiday list

Below is the logic to calculate the business working hours between to dates

Here is the output


2) Calculate business working hours excluding week ends(Saturday and Sunday), Lunch Breaks and Holidays.

Below are the considerations

1) Count only standard working hours ( 9 AM - 6 PM)

2) Exclude Saturdays and Sundays

3) Exclude Lunch Break (1 PM - 2PM)

4) Exclude Holidays

Set the Variables for standard working hours and lunch breaks. You can change the values according to your needs

Include the Holidays

Below is the logic to calculate the business working hours between two dates



Here is the output


If you want to present the working hours in hh:mm:ss format then you can use below logic after calculating working hours


Please see the attached QVW.

Feel free to provide any suggestions.

Tags (1)
Not applicable

I would like to thank kush141087‌ for the remarkable post with all these information. It is very rich and helped me a lot!

I just need a little help to understand what *24, 0.001 is doing.

The main structure of the script is like:




          )*24, 0.001


) AS Business_Hrs_Without_Overtime

I still can't understand why *24 and 0.001 are necessary and how they work along the rest of the script.

Besides, I would like to call on for some more help about the output from the outer rangesum().

What I've understood about the whole post is how " calculate the business working hours between two Dates".

I've came across throught some not so easy to catch on results while running the script. For example, I have two dates:

START_TIME = 23/10/2018 09:18

END_TIME = 23/10/2018 09:24

If I use these two dates on the Script, the outer rangersum() (Business_Hrs_Without_Overtime) gives me 0,11 as output.

I just don't know what I should do with this output to get, or even transform to, an Hour that make sense with the whole scope. I mean, the main ideia is to get the business working hour between two given timestamps, right? But the output from this outer rangersum() is a simple number.

If I take this number and cast a Date(), Timestamp() or Time() the result is just some random date and time.



    START_TIME = 23/10/2018 09:18

    END_TIME = 23/10/2018 09:24

    Business_Hrs_Without_Overtime = 0,11

    Timestamp(Business_Hrs_Without_Overtime) = 30/12/1899 02:38:24

Can someone help me understand how to take Business_Hrs_Without_Overtime output and transform into a correct Time?

I'll be really appreciate.

Thanks, friends.


Good work Kushal,



If my holidays are going to vary from branch to branch or region to region, how it can be incorporated in the above logic.

Contributor II
Contributor II

Good job. Its very useful ....Thanks


Hallo, I am new in Qlik Sense. I have one question...

How to "convert" the Minutes? for example in you first table on line 5 is "7.98" how can i get the exact minutes of 98? or also in the first table the last line 16.5 how can i get 16:30?


Thank you!


Hello Kush,


Very interesting but 'overtime' seems not to work when we only have working hours outside of office hours.

working hours : 9-14 15-19

Example : start date 08:00:00 end date 08:39:00

Overtime should be 00:39:00 and your formula shows something else

please see this post for more details


Thank you !


Just a question in terms of the loading of dates from different tables

When the StartTime and EndTime load from the same table the script works perfectly. I have the StartTime and Endtime in two different tables. The StartTime loads  but the EndTime doesn't , error message : Field 'EndTime' not found. Does this script only work when loading from one table?

timestamp(timestamp#(StartTime,'MM/DD/YYYY hh:mm:ss TT')) as START_TIME,
timestamp(timestamp#(EndTime,'MM/DD/YYYY hh:mm:ss TT')) as END_TIME;

Timestamp(Timestamp#([StartTime], 'YYYY-MM-DD hh:mm:ss TT') ) AS [StartTime]
FROM [lib://QS/FinancialTransaction.qvd](qvd);

Timestamp(Timestamp#([EndTime], 'YYYY-MM-DD hh:mm:ss TT') ) AS [EndTime]
FROM [lib://QS/VendorJob.qvd](qvd); 


Have a good day!

Partner - Creator
Partner - Creator

@Kushal_Chawda  @Sunny 

Hi Kush,

can you please help me to calculating the time diff between two dates based on given points

1- First I have to calculate the time weekdays in between 7 Am to 11 PM excluding sat and sun . am using below script for this but prob is that when both the dates are weekend then its also calculate the time diff  .

if(not WildMatch(IssueStatus,'Pending') , (Interval((RangeMin(frac(IssueResolutionDate), MakeTime(23))- RangeMax(frac(IssueCreateDate), MakeTime(7)))+
( NetWorkDays(IssueCreateDate, IssueResolutionDate-1) * MakeTime(16)) ))) as TotalTime,

2- Second I have to calculate the time diff only Weekend Sat or Sun in between 10 Am to 4 PM . also if any dates is weekend and other one is weekday then it calculate the time based on diff time difference .

3- if any ticket open in the last month and closed in next month then it calculate the time as point 1 except if it comes on weekdays .

Please help me to find the correct result 



How to proceed if I have vStartHour=5, vEndHour=2 ?

Contributor II
Contributor II

Hi All,

It would be very grateful if any one can help me to get expression  vStartHour=10.30am, vEndHour=6.30pm.


Version history
Last update:
‎2022-09-21 01:04 PM
Updated by: