Python3 Count Number of Week Days Ignoring Holidays - python-3.x

Testing one of my scripts it appears that Numpy busday_count includes Labor Day (September 2nd). Is there a way to disable the holidays?
print (np.busday_count('2019-08-31', '2019-09-02'))
Result = 0, but 9/2/2019 is clearly Labor Day and a Monday.
print (np.busday_count('2019-08-31', '2019-09-03'))
Result = 1, but it should be 2. As far as I know the formula excludes the first date but includes the second date. I also tried:
print (np.busday_count('2019-08-31', '2019-09-02', holidays=[]))
Result still = 0 despite attempt to clear any holidays. What am I missing?

As so often, the answer lies with the documentation and Python's love for half-open intervals:
Counts the number of valid days between begindates and enddates, not including the day of enddates.

Related

Is there an excel function that I can use to give values based on what the time value is?

I'm looking for a function I can use that returns "Night Off Prime" if the time a programme was on was between 11pm - 5:59am, "Day Off Prime" if it was on between 6am - 5:59pm and "Prime" if it was on between 6pm - 10:59pm.
I've tried using the IFS function with the code being =IFS(OR(G3>=23,G3<6),"Night Off Prime", OR(G3>=6,G3<18),"Day Off Prime", OR(G3>=18,G3,23),"Prime")
The G column is just the hh format of the hour it was on, with the values formatted as Number.
I've also tried =IFS(OR(BK3>=23:00,BK3<06:00),"Night Off Prime", OR(BK3>=06:00,G3<18:00),"Day Off Prime", OR(BK3>=18:00,BK3,23:00),"Prime")
Here the BK column is the time the programme was on in the hh:mm time format
The main trouble I'm finding there is how to label time between two different times such as between 11pm - 5:59am instead of just past 11pm. I used the OR logical but that doesn't seem to have worked.
I've also tried a VLOOKUP function =VLOOKUP(BK2,$AC$899:$AD$901,2, TRUE)
Here the table array is
AC899 Night Off Prime AD899 23:00-05:59
AC900 Day Off Prime AD900 06:00-17:59
AC901 Prime AD901 18:00-22:59
If you prefer the IFS you may want to adjust like this (should work in the similar way for hh:mm as well):
=IFS(G3<6;"Night Off Prime";G3<18;"Day Off Prime";G3<23;"Prime";TRUE;"Night Off Prime")
(may replace ; with , depending on regional setting)
alternatively:
=IFS(G3<0;"#N/A";G3<6;"Night Off Prime";G3<18;"Day Off Prime";G3<23;"Prime";G3<24;"Night Off Prime";TRUE;"#N/A")
"The main trouble I'm finding there is how to label time between two different times such as between 11pm - 5:59am instead of just past 11pm."
Add a column H2 = G2 + 1/24
Then your ranges are 0 to 7/24, 7/24 to 19/24 and 19/24 to 24/24, so you don't have an interval split over a resetting of the clock to zero.

Need to change date into current work week (1-52), but skip to the next week if the day is Wed - Sat in VBA

I'm having trouble writing code in VBA that would allow me to input any given date then have an output of the current work week. I need a restriction of if the date is Sunday through Tuesday, it will keep that current work week and year but if the date is Wednesday through Saturday, then the next work week and year will show. For example, I'm looking to input (5/28/19) and have an output of 201922 or an input of (5/29/19) with an output of 201923 even though its technically the same work week.
Before getting too in depth, I do have a working function that provides the year and work week, but I'm trying to adapt the function or add a separate function that will change in to the next work week according to the given date.
I'm new to VBA but have tried to do a little research over the last few days. I was thinking that I could somehow have one input of the date then have two outputs where one would be the year and work week then the other would be the number associated with that date (1 for Sunday, 2 for Monday, and so on). I tried to create an if then statement that says if the number associated with that date is 1, 2, or 3 then the workweek would stay the same. If it was any other number then 1 would be added to that work week so it would move to the next one. I'm having trouble with trying to make two outputs and have them connected, if that makes any sense.
This is the code that I tried to create, but continuously failed at making. The function that gives the correct work week (without the adaptation of the work week based on the date weekday) is WWV1
Function WWV2(WeekdayName As Integer)
Dim WWV1 As Integer
If WeekdayName(Date) = 1 Or 2 Or 3 Then WWV1 = WWV1
Else: WWV1 = WWV1 + 1
End Function
This provides the cell with #NUM! when I use the function in that cell, which I assume is because I need to somehow connect the two functions.
how about this:
=YEAR(A1) & TEXT(WEEKNUM(A1,13),"00")
WeekNum returns the weeknumber with 13 saying it starts on Wednesday:
VBA
wkcd = Year(Range("A1")) & Format(Application.WeekNum(Range("A1")),"00")

Determine number of days (not including weekend) based on hours given

I have two important details that are inputted into an excel table, Job_Start_Date and Job_Hours (meaning the hours required to complete the job). Given certain working hours (eg 7:00am-3:30pm) I need to calculate what day and what time they will finish. I already have that basic bit working, but I cannot for the life of me figure out how to skip weekends in that calculation (Note that there is a boolean for Sat/Sun that defines whether that day should be skipped).
Here is an example of the data
and an example of the data visualization: (The DIV errors are because employee count equals 0, pay this no mind.)
.
This is the formula used in the visualizer (a massive index match)
=IFNA(INDEX(INDIRECT(Allocation!$A$1), MATCH(1,($A3 = INDIRECT(Allocation!$K$1))
* (C$1 >= INDIRECT(Allocation!$C$1)) * (C$1 <= INDIRECT(Allocation!$D$1))
* IF(C$1 = INDIRECT(Allocation!$C$1), ($B3 >= INDIRECT(Allocation!$E$1)),
($B3 >= INDIRECT(Allocation!$I$1))) * IF(C$1 = INDIRECT(Allocation!$D$1),
($B3 < INDIRECT(Allocation!$F$1)), ($B3 < INDIRECT(Allocation!$J$1))), 0)),"")
As you can see in the image, Saturdays need to be skipped (being FALSE), but it is still shown on the visualizer. However, if I include a statement that matches the Saturday condition (so it only shows up on a Saturday if TRUE), it will not alter the end date and thus will not push the final day to Monday.
Essentially the question is: How can I skip days but preserve the 'working hours'. This must be done in excel formulas in the same Job table (first image).
Thanks.
Here is how I got it working using WORKDAY.INTL.
First is a nested IF to determine which weekend type to use for the workday.intl function
Weekend=IF(OR([#[JOB SATURDAY]], [#[JOB SUNDAY]]), IF(AND([#[JOB SATURDAY]], [#[JOB SUNDAY]]), -1, IF([#[JOB SATURDAY]], 11, 17)), 1)
Then a second if statement that references that value and then spits out the correct date
=IF([#[Weekend]] = -1, [#[JOB START DATE]]+[#[Working Days]], WORKDAY.INTL([#[JOB START DATE]], [#[Working Days]], [#[Weekend]]))

Excel split cost figure between months with partial dates

I have a list of cost figures with start dates and end dates which I need to split between months, I have searched for the solution to this problem but cannot seem to find one that will work with partial months i.e.( startdate:01/01/2015 enddate: 15/04/2015 cost:10000) which would leave figures like Jan:2857, Feb:2857, Mar:2857, Apr:1429.
I have been trying to modify this example: http://www.excel-university.com/excel-formula-to-allocate-an-amount-into-monthly-columns/ but having no luck getting the partial months working.
Any suggestions or help would be most welcome. Thanks in Advance
if you calculate it on daily basis, would it be ok? the result would be:
01.01.2015 01.02.2015 01.03.2015 15.04.2015
2.857,14 2.857,14 2.857,14 1.428,57
your daily amount is:
=10.000/(DAYS360(startdate;enddate;TRUE)+1)
(be carefull of true and false argument)
under the dates or instead of 2.857,14 etc. insert the formula:
=IF(DAY("your date")>1;DAY("your date");30) * daily amount
This formula assumes that you want to have 30 days in each month:
=IF(DAY(01.01.2015)>1;DAY(01.01.2015);30)
result = 30
=IF(DAY(15.04.2015)>1;DAY(15.04.2015);30)
result = 15
so if months begins with a date different from the 1st it will give you the number of days.
if you want to match months with your startdate and enddate (if i understood your comment correctly), you could do:
=IF(OR(
AND(MONTH(startdate)=MONTH(your date);YEAR(startdate)=YEAR(your date));
AND(MONTH(enddate)=MONTH(your date);YEAR(enddate)=YEAR(your date))
);"match";"no match")
by this you make sure that month and year correspond.
If you want to get the number of days in a month automatically, you could use:
=DAY(DATE(YEAR("your date");MONTH("your date")+1;1)-1)
but this does not assume anymore 30 days, you can change it with if statement
I hope this helps,
Best - AB

Formula to compare time values

Below excel formula is working fine but in some cases its not give me proper value .
Input:
19:20:42
24:58:36
26:11:18
After using this formula:
=IF(TIMEVALUE(K7)>TIMEVALUE("09:00:00"),TRUE,FALSE)
I got the below output:
FALSE
TRUE
TRUE
What I Observe if the time value is > or = 24:00:00 it will not give me the proper answer.
How do I fix this?
As an alternative to Captain's excellent answer, you could also use:
=IF(K7>(9/24),TRUE,FALSE)
DateTime values are internally stored as a number of days since 1/1/1900,
therefore 1 = 1 day = 24 hours. So 9/24 = 0.375 = 9 hours :-)
You can easily verify this by clearing the format of your DateTime cells.
Edit: note that such Boolean formula can be expressed in a shorter way without losing legibility:
=K7>(9/24)
When you go over 24 hours, Excel counts it as the next day... and then the TIMEVALUE is the time the next day (i.e. 00:58:36 and 02:11:18 in your examples) and can, therefore, be before 0900.
You could do DATEVALUE(K7)+TIMEVALUE(K7) to ensure that you count the day part too...

Resources