Excel formula: how to sum total time between different time intervals based on a time condition - excel

A B
Departure Date Arrival date
4/9/18 22:40 5/17/18 14:10
8/5/18 18:20 8/22/18 6:00
9/24/18 22:20 10/10/18 6:00
10/22/18 14:00 11/7/18 6:10
12/3/18 22:25 12/19/18 6:00
1/16/19 0:00 1/30/19 0:00
I need some help please. I have to calculate the total travel days for our employees for a specific period of time. I have columns A and B (all are date and time). Column A is the Departure Date, Column B is the Arrival Date.
Question: which is the Total number of travel days between:5/10/2018 and 12/10/2018?

Try this, you may need to edit it to match your needs though...
IF(AND(A4>=$A$1,B4<=$B$1),B4-A4,IF(AND(A4<=A$1,B4<=$B$1),B4-$A$1,IF(AND(A4>=A$1,B4>=$B$1),$B$1-A4)))
See:

Related

How to get time elapsed till 12:00 AM in same day and rest on next day

I am currently facing difficulty to calculate exact hours between In Time and Out time.
for instance :
Column A
Column B
Column C
Column D
1-1-2022
10:00 PM
1-2-2022
6:00 AM
1-2-2022
10:00 PM
1-3-2022
6:00 AM
Now, my problem is that I have to calculate the time from 10:00 PM till 12:00 AM = 2 Hours and rest to be calculated on the next day adding the previous days hours e.g. we have 6 hours from 12:00 AM till 6:00 AM for 1-2-2022 (Column C) and then 2 hours from 10:00 PM to 12:00 AM.
Looking forward your help.
You must add the date and times together, subtracting the In time from the Out time.
Slightly different method:
B2, D2 and E2 formatted as hh:mm
Then you could use mod() like so:
=MOD(D2-B2,1)

Allocating staff to 30 minute intervals

I’m trying to create either a spreadsheet or macro that allows me to put and employee start and finish time in and then show me by each half hour how many half hours they are in.
For example;
Employee 1 - 08:30 to 10:15
The output I would want is;
08:00 0
08:30 1
09:00 1
09:30 1
10:00 0.5
10:30 0
11:00 0
So between 8:30 and 9:00 shows as one because that employee was in during that half hour. But between 10:00 and 10:30 it shows 0.5 because the employee was only in for half of that period
Then as I add more data it tells me which half hours they are covering.
I’ve tried using the ceiling and floor values, counta, countif, countifs, v and hlookups but just can’t get the desired effect.
I’m guessing it would need to be a macro.
Assuming C1 and D1 contain the start and end times of a shift and column A contains the times, use the following formula in column B:
=IF(A2>D$1,C2,IF(AND(A2>=C$1,A3<=D$1),1,MAX(0,A3-D$1)/(1/48)))
Limitations: shifts cannot cross over days, days cannot start before 00:00 or end after 23:59

How to split the time between two dates over daily columns

I am in much need of help please.
I have the table below.
It has about 300 rows and columns on the right for each day of the year starting 2015, ending 2019. I only entered a few columns here as an example.
What I need:
A formula to split the time (it can be hours or decimal days, it doesn't matter) between the two days on the left on the columns to the right.
In the rest of the days, which are not included in the period, I need a zero in those columns.
I manually entered the results I need so it can help you understand.
E.g.
On the first row:
The employee has spent
15 hours at destination in the first day of travel,
24 hours in the second day of travel
11:50 hours in the last day of travel.
All the rest of the columns to the right, which are not here, starting 1/4/2015 23:59 should give the result zero.
Thank You!!
Entry Date Exit Date 1/1/2015 23:59 1/2/2015 23:59 1/3/2015 23:59
1/1/15 9:00 1/3/15 11:50 15.00 24.00 11.50
As far as I can tell, it boils down to this
1.0 days 2.0 days 3.0 days 4.0 days
period=p in h/d.d p-(1-(so far)) p-(2-(so far)) p-(3-(so far)) 0
EDIT 2: I've come up with a formula.
NOTE:
This formula assumes existence of a column that specifies 0 hours of work between the "end date/time" column ("B") and first work hour ("D"), so you have it like this:
A B C D E F G H
1 Entry Date Exit Date ZERO 1/1/2015 23:59 1/2/2015 23:59 1/3/2015 23:59 1/4/2015 23:59 1/5/2015 23:59
2 1/1/15 9:00 1/3/2015 11:50 0 0.6243055556 1 0.49375 0 0.00
3
The extra column is there to avoid circular dependencies, since
we must "iteratively" accumulate the hours
The main formula for row 2 from column D being:
=MIN(D1-$A2,MIN(MAX(($B2-$A2) - SUM($C2:C2), 0),1))
Note: semicolons may be needed instead of commas in Excel as delimiters.
Note: the last digit in the formula depends on the unit. Here it is in days decimal. If hours, put 24.
In plain English, for a cell
Calculate sum of hours/days decimal in the range C to wherever - 1
Subtract result from the difference between start and end (total hours)
If less than 0, put 0 (MAX(x, 0))
If more than 1, put 1 (MIN(x, 1))
Choose between the result, or the difference between current date and start time, if it is smaller

Finding earliest date in excel

In one column I have to 10 times and dates (I have merged date and time in a cell). How do I find top 5 earliest dates and times? I can’t use function MIN() because I have date and time together. How should I write the function?
You need to first format your data in date/time format in Excel.
Example, the following data is entered
16/7/2018 15:00
18/7/2018 12:05
25/8/2018 11:00
13/7/2018 09:00
15/7/2018 14:00
15/7/2018 11:00
You can use the formula =small(range, rank) to find the smallest n figure. For instance, =SMALL($A$1:$A$6,1) would give the smallest (earliest) date, 13/7/2018 09:00 in this case. =SMALL($A$1:$A$6, 2) would give the second smallest (earliest) date, 15/7/2018 11:00 in this case.

Determine if time is before or after specific time

I have an Excel sheet with two date-time columns: Start Date and End Date. I need to calculate overtime by determining how many hours and minutes were worked before 08:00 and after 16:30.
Examples:
COLUMN A COLUMN B
1 2017/01/04 16:00 2017/01/04 18:00
2 2017/01/05 18:00 2017/01/05 21:00
3 2017/01/08 08:00 2017/01/08 17:00
4 2017/01/09 07:00 2017/01/09 09:00
I know the calculation for duration between times (=TEXT(B1-A1,"h:mm")), but I'm struggling to determine if a date-time is before 08:00 or after 16:30.
I've played around with TIMEVALUE("8:00:00"), TIMEVALUE("8:00:00 AM") and TIME(8,00,00) in my calculation, but the it did not work,
e.g. =IF(A1<=TIMEVALUE("8:00:00 AM"),"Yes","No") returns "No" even for A4 (2017/01/09 07:00)
I'm struggling with the calculation and the logic on this one. So far i'm using,
=IF(MOD(F2,1)<8/24,8/24-MOD(F2,1),0)+IF(MOD(G2,1)>16.5/24,MO‌​D(G2,1)-16.5/24,0)
Try this:
=IF(TIMEVALUE(A1)<=TIMEVALUE("8:00:00 AM"),"Yes","No")
Stick with treating time as time; only treat time as text when you have bad data (time as text is bad data) and then only enough to get it to be time as time.
To get the number of hours and minutes before 08:00 AM,
=MAX(0, TIME(8, 0, 0)-TIMEVALUE(TEXT(A2, "hh:mm;0;#")))
To get the number of hours and minutes after 16:30 AM,
=MAX(0, TIMEVALUE(TEXT(B2, "hh:mm;0;#"))-TIME(16, 30, 0))
In the following image you can see that I have left one group as true time and the forced the following group to be time as text¹. Both return correct results.
¹ Unless specifically formatted otherwise, numbers and dates/times are right-aligned in a cell; text is left-aligned.

Resources