Skip to main content

Number of weekdays and weekend days between 2 dates

Dear all ,
 
As per subject what is the easier way to find out the exact number of working days and weekend days that occur between 2 dates (regardles of public holidays).
Lets analyse the below example:
Start Date          End Date
02/01/2019        15/01/2019
Equation: End Date - Start Date
Result: 10 working days, 4 weekend days
I know that i could potentially use: @Dow and @Workday functions in IDEA but without counting first the number of days between both dates and then using nested Ifs statements I cannot see it working.
 
Any tips are much appreciated.
 
 
 
 

ravisdxb Fri, 02/01/2019 - 13:47

In reply to by borderraux

@borderraux: I included the strings "nn weekdays, nn weekend days" since you asked for it in your original post. However, you are able to modify the code and get the results you want. Good job. It is an interesting learning process.
 
By the way, the Python code returns 4,0 but your data shows 3 and 0.. This may be due to including/excuding both the dates in the calcuation instead of the gap between the 2 dates. You need to determine which logic is applicable for your specific requirement.
 
Regards,
Ravi

borderraux Mon, 02/04/2019 - 08:49

In reply to by ravisdxb

@ravisdxb , thank you ravi - i am completely new to Python programming (only used VBA in the past and IDEA scripting for the last 6m) so it will be a learning curve to accomodate Python potential into IDEA but taking into consideration how much you can achieve by incorporating python script into IDEA this is a way to go. I have started some online course on panda python as the library offers great options for data munging and cleansing so hopefully at some point in the future i will be able to write some functions in Python to be used in IDEA.
with regards to my data: yes , you are correct that my data shows 3 and 0 - this is the calculation I have done in Excel before exporting the file in to IDEA - I am dealing with hotel booking data hence the difference in my analysis and the results generated by your function (the python function takes into consideration each day within range of dates - start data, end date and all between while for my analysis I need only the night booked by the guests hence the difference).
Thank you for your help.

ravisdxb Mon, 02/04/2019 - 15:32

In reply to by borderraux

@borderraux: All the best on your journey with Python.
 
If you need 3,0 instead of 4,0 as the result, you just need to modify the code as below:
From: xdays=(xtodate-xfromdate).days+1
To: xdays=(xtodate-xfromdate).days
 
Cheers
Ravi

Bert_B Tue, 04/23/2024 - 07:41

Sorry, this post can be deleted.