Time calculations

tigerzen

Board Regular
Joined
Mar 8, 2023
Messages
165
Office Version
  1. 365
Platform
  1. Windows
Need to work out what I thought was simple enough but basically need to return if an incident occurred after midnight. Also a formula to calculate the difference between the time of the incident compared to a selected threshold time eg if the threshold time was 11:30 pm then how long after that was the incident? I've included required output to help explain the situation. The problem is that the data comes in with the time as text and doesn't allow any meaningful calculations. The threshold time is to be set dynamically.

Book1
ABCDEFG
1Staff Time occurredAfter midnightHow long after ThresholdThreshold
2Friday12:18
3Thursday10:50
4Wednesday10:47
5Tuesday11:31
6Monday10:32
7Sunday11:48
8Saturday1:41
9
10Required ouptut
11Staff Time occurredAfter midnightHow long after ThresholdThreshold11:45
12Friday12:18Yes33
13Thursday10:50
14Wednesday10:47
15Tuesday11:31
16Monday10:32
17Sunday11:483
18Saturday1:41 Yes116
Sheet1
Cell Formulas
RangeFormula
D12D12=33
 
I'll post another sample which is more relevant to the issue. Shifts begin from 10 pm onto 6 am, please ignore the previous CSV data, on this one anything 22 or 23 would be 10 pm and 11 pm respectively. Anything else eg 01:34 would be 1:34 am.
13-4-2023.xlsx
A
22022-02-19T23:58:00+11:00
32022-02-21T00:23:00+11:00
42022-02-21T23:30:00+11:00
52022-02-23T01:32:00+11:00
62022-02-23T23:49:00+11:00
72022-02-23T23:49:00+11:00
82022-02-25T03:16:00+11:00
92022-02-25T20:11:00+11:00
102022-02-27T00:02:00+11:00
112022-02-27T23:23:00+11:00
122022-03-01T00:40:00+11:00
132022-03-02T03:45:00+11:00
142022-03-03T05:29:00+11:00
152022-03-04T00:10:00+11:00
162022-03-04T23:36:00+11:00
172022-03-06T00:39:00+11:00
182022-03-07T00:55:00+11:00
192022-03-07T22:58:00+11:00
202022-03-08T23:27:00+11:00
212022-03-11T00:43:00+11:00
222022-03-12T00:27:00+11:00
232022-03-13T00:18:00+11:00
242022-03-14T00:04:00+11:00
252022-03-14T23:11:00+11:00
262022-03-15T23:32:00+11:00
272022-03-16T23:21:00+11:00
CSV
okay, and should we ignore the +11? Is that saying you are in time zone +11 or that you need to add 11 to get your correct time?
 
Upvote 0

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
this is assuming the time portion of the csv is the time in your time zone. (I did not add the +11:00:00)
It is so much easier when you use entire date-time values. Please look at what value is in cell H1.
if your threshold value needs to change, then I suggest putting that in a column of its own and manually changing it as you see fit. Otherwise any prior calculations will be corrupted when you make subsequent changes to the threshold (unless you copy/paste those prior calculations to values after they are completed, which is risky as you would cause errors if you forget to do that).

mr excel questions 24.xlsm
ABCDEFGH
1csv time stampStaff Time occurredAfter midnightHow long after ThresholdThreshold2022-02-19 23:45
22022-02-19T23:58:00+11:00Saturday23:5800:13
32022-02-21T00:23:00+11:00Monday00:2324:38
42022-02-21T23:30:00+11:00Monday23:3047:45
52022-02-23T01:32:00+11:00Wednesday01:3273:47
62022-02-23T23:49:00+11:00Wednesday23:4996:04
72022-02-23T23:49:00+11:00Wednesday23:4996:04
82022-02-25T03:16:00+11:00Friday03:16123:31
tigerzen
Cell Formulas
RangeFormula
H1H1=DATE(2022,2,19)+TIME(23,45,0)
B2:C8B2=DATEVALUE(TEXTBEFORE($A2,"T"))+TIMEVALUE(TEXTBEFORE(TEXTAFTER($A2,"T"),"+"))
E2:E8E2=C2-$H$1
 
Upvote 0
Thanks awoohaw, I think it's close but column E is the difference in time, the days should not be included in the calculation, so cell E3 should be 38 mins.
 
Upvote 0
i'm confused. 11:45 to 11:58 is 13 minutes. Can you show me what numbers (cells and their values) are supposed to be compared?

at what values are expected in E4:E9?

And i'm not sure what you mean by excluding days (dates). I did not see (It may be there, but I didn't see) any requirement regarding that.
I'm happy to address that but, I need more explanation of your desired output,
Thanks awoohaw, I think it's close but column E is the difference in time, the days should not be included in the calculation, so cell E3 should be 38 min
 
Upvote 0
Thanks awoohaw, I think it's close but column E is the difference in time, the days should not be included in the calculation, so cell E3 should be 38 mins.
My experience is not the defacto convention of doing things. But Dates are in-extricably asscociated with time, especially when you are calculating time differences over a midnight -I absolutely need to have a day in the calculation (even if it is 1/1/1900 1:00 AM compared to a start time on 1/0/1900).
 
Upvote 0
i'm confused. 11:45 to 11:58 is 13 minutes. Can you show me what numbers (cells and their values) are supposed to be compared?

at what values are expected in E4:E9?

And i'm not sure what you mean by excluding days (dates). I did not see (It may be there, but I didn't see) any requirement regarding that.
I'm happy to address that but, I need more explanation of your desired output,
In your post #12 above, the difference should be 38 mins in E3 but you have 24:38, it comes down to whether you include the days transpired rather than just the time but I think one of your subsequent posts might explain this.
 
Upvote 0
In your post #12 above, the difference should be 38 mins in E3 but you have 24:38, it comes down to whether you include the days transpired rather than just the time but I think one of your subsequent posts might explain this.
yes, you will likely run into this problem regardless if the threshold time is a time on day zero or a date-time value. What ever you subtract this time from you will have a difference with the date time of the row (unless you only use a time, but then you will miss the beyond midnight calculations or have to include more calculations in it).
 
Upvote 0

Forum statistics

Threads
1,215,096
Messages
6,123,074
Members
449,093
Latest member
ripvw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top