Calculate shift from date/time value

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,404
Office Version
  1. 2016
Platform
  1. Windows
I have a range of cells formatted as custom "dd/mm/yyyy hh:mm" and I'm trying to get the shift type from the time value as follows;

If between 0630 and 1430 then shift is Early
If between 1430 and 2200 then shift is Late
If between 2200 and 0630 then shift is Night

I've tried all sorts of variations using formulas and VBA routines but nothing works as I would expect.

Can anyone start me off please?

I don't mind if this is accomplished using formulas or VBA.
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
tried to find the post from yesterday -not on this forum
same sort of thing
shift 1 ,2,3
so as you have overlapping time - is it up to 14:29 ??? on the shifts so less than <14:30

=IF(OR(A2-INT(A2)>=TIMEVALUE("10:00 PM"),A2-INT(A2)<TIMEVALUE("6:30 AM")),"Night",IF(A2-INT(A2)<TIMEVALUE("2:30 PM"),"Early","late"))
Note the use of < and < =
so that may change

for example
>=TIMEVALUE("10:00 PM") - which includes 10pm
<TIMEVALUE("6:30 AM")) - which excludes 6:30
for "Night shift



see how that works out

Formula to determine shift.xlsx
AB
1Date-TimeShift
28/1/22 5:00Night
38/1/22 22:30Night
48/2/22 15:00late
58/3/22 21:00late
68/3/22 10:00Early
78/3/22 13:45Early
88/5/22 0:30Night
98/5/22 19:30late
108/7/22 1:08Night
118/8/22 3:30Night
128/8/22 12:18Early
138/8/22 12:18Early
148/8/22 22:00late
158/10/22 1:17Night
168/15/22 0:00Night
178/15/22 4:28Night
188/19/22 16:40late
198/27/22 23:03Night
Sheet1
Cell Formulas
RangeFormula
B2:B19B2=IF(OR(A2-INT(A2)>=TIMEVALUE("10:00 PM"),A2-INT(A2)<TIMEVALUE("6:30 AM")),"Night",IF(A2-INT(A2)<TIMEVALUE("2:30 PM"),"Early","late"))


Note: Images are difficult to see , and also requires that I input all the data myself, which means I may make an error, which is very time consuming, and from my point of view less likely to get a response, if a complicated spreadsheet. Plus we cannot see any of the formulas used.

Therefore -

A SMALL sample spreadsheet, around 10-20 rows, would help a lot here, with all sensitive data removed, and expected results mocked up and manually entered, with a few notes of explanation.

MrExcel has a tool called “XL2BB” that lets you post samples of your data and will allow us to copy/paste your sample data into our Excel spreadsheets, saving a lot of time.

You can also test to see if it works ok, in the "Test Here" forum.

OR if you cannot get XL2BB to work, or have restrictions on your PC , then put the sample spreadsheet onto a share
I only tend to goto OneDrive, Dropbox or google docs , as I'm never certain of other random share sites and possible virus.
Please make sure you have a representative data sample and also that the data has been desensitised, remember this site is open to anyone with internet access to see - so any sensitive / personal data should be removed
 
Upvote 0
Solution
You are amazing, that works exactly as I need!

Thank you so much etaf!
 
Upvote 0
you are welcome - actually i created a more complicated formula for this on a different forum , and another member came up with simplified solutions , which i often copy for future use
 
Upvote 0

Forum statistics

Threads
1,215,338
Messages
6,124,360
Members
449,155
Latest member
ravioli44

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