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.
EDIT: Forgot to add the current formula (see bottom of post)
I have multiple columns that store time as interval values (e.g. 10PM stored as 22, 6AM stored as 06) - see image
I need to check if a certain time is between all the different time intervals
How do I write an Excel formula that checks if a time is between
multiple time intervals (e.g. is 2:30AM in between 10PM and 4AM?)?
My time intervals are stored in columns:
J5&K5 [i.e. J5 is the start (value: 02) and K5 is the end (value: 12)]
L5&M5
N5&O5
P5&Q5
R5&S5 [i.e. R5 is the start (value: 06) and K5 is the end (value: 18)]
The times I would like to check are in T1:AE5
e.g. T1 = 6:30AM
e.g. U1 = 8:30AM
e.g. AD1 = 02:30AM
e.g. AE1 = 04:30AM
Example (see image):
Count the number of times AD1 is in between:
J5&K5
L5&M5
N5&O5
P5&Q5
R5&S5 (i.e. R5 is the start and K5 is the end)
In this example, the count should be 3 and stored in AD5 (it's in between J5&K5,
L5&M5, N5&O5)
Things to consider:
00:00 and 24:00 are both stored as 24
Sometimes the start time is at night (e.g. 22, 24) and the end time is in the morning (e.g. 02, 04, 06)
Sometimes the start time is in the morning (e.g. 02 or 04) and the end time is in the afternoon (e.g. 14 or 16)
Current formula in AD1 (which can't account for the fact that 2.5 is actually in between 24 and 06)
=SUMPRODUCT(($AD$1>INDEX(J4:S4,1,N(IF(1,{1,3,5,7,9}))))*($AD$1<INDEX(J4:S4,1,N(IF(1,{2,4,6,8,10})))))
^Note this is a formula provided by another Stackoverflow member when I had a somewhat simpler problem to tackle before the requirement changed
Breaking down the formula you have:
=SUMPRODUCT(($AD$1>INDEX(J4:S4,1,N(IF(1,{1,3,5,7,9}))))*($AD$1<INDEX(J4:S4,1,N(IF(1,{2,4,6,8,10})))))
$AD$1>INDEX(J4:S4,1,N(IF(1,{1,3,5,7,9}))) checks if AD1 is greater than the start time
$AD$1<INDEX(J4:S4,1,N(IF(1,{2,4,6,8,10}))) checks if AD1 is less than the end time
Then the results are multiplied. Since True evaluates to 1 and False to 0, the multiplication only results in 1 where both conditions are met.
In logical terms:
AD1 is greater than the start time
AND
AD1 is less than the end time
The additional logic required is to count the instances where:
AD1 is greater than the start time
OR
AD1 is less than the end time
WHILE
the start time is greater than the end time
This is accomplished with:
=SUMPRODUCT((($AD$1>INDEX(J4:S4,1,N(IF(1,{1,3,5,7,9}))))+($AD$1<INDEX(J4:S4,1,N(IF(1,{2,4,6,8,10})))))*(INDEX(J4:S4,1,N(IF(1,{1,3,5,7,9})))>INDEX(J4:S4,1,N(IF(1,{2,4,6,8,10})))))
$AD$1>INDEX(J4:S4,1,N(IF(1,{1,3,5,7,9}))) checks if AD1 is greater than the start time
$AD$1<INDEX(J4:S4,1,N(IF(1,{2,4,6,8,10}))) checks if AD1 is less than the end time
This time these get added together (OR'd)
INDEX(J4:S4,1,N(IF(1,{1,3,5,7,9})))>INDEX(J4:S4,1,N(IF(1,{2,4,6,8,10}))) checks that the start time is greater than the end time
This third check gets multiplied (AND'd) with the result of the prior addition. This results in only counting situations in which the start time is at a later time than the end time (overnight) and for which AD1 is during the time period.
So to count all the desired situations, you should use the sum of both the original and the new parts:
=SUMPRODUCT(($AD$1>INDEX(J4:S4,1,N(IF(1,{1,3,5,7,9}))))*($AD$1<INDEX(J4:S4,1,N(IF(1,{2,4,6,8,10})))))+SUMPRODUCT((($AD$1>INDEX(J4:S4,1,N(IF(1,{1,3,5,7,9}))))+($AD$1<INDEX(J4:S4,1,N(IF(1,{2,4,6,8,10})))))*(INDEX(J4:S4,1,N(IF(1,{1,3,5,7,9})))>INDEX(J4:S4,1,N(IF(1,{2,4,6,8,10})))))
Well, not the cleanest formula in the world, but at least it works. I'm sure there is a way to resume this formula, but I'm such a noob with SUMPRODUCT and I could not find a way.
I got this:
The formula I've used in cell A3 is:
=SUM(IF(B7<A7;IF(Y(A1+24>=A7;A1+24<=B7+24);1;0);IF(Y(A1>=A7;A1<=B7);1;0));IF(D7<C7;IF(Y(A1+24>=C7;A1+24<=D7+24);1;0);IF(Y(A1>=C7;A1<=D7);1;0));IF(F7<E7;IF(Y(A1+24>=E7;A1+24<=F7+24);1;0);IF(Y(A1>=E7;A1<=F7);1;0));IF(H7<G7;IF(Y(A1+24>=G7;A1+24<=H7+24);1;0);IF(Y(A1>=G7;A1<=H7);1;0));IF(J7<I7;IF(Y(A1+24>=I7;A1+24<=J7+24);1;0);IF(Y(A1>=I7;A1<=J7);1;0)))
The idea is just check if End is less than Start. If true, because you are working with periods of 24 hours, then sum 24 to End and also to value being checked.
After that, it just check if the value is between Start and End.
But yeah, pretty dirty. I'm posting the formula, hoping somebody can resume it.
But as I said, at least it works.
Here is one way solving the issue by using two helper rows (if that's an option):
The purpose of the helper rows is to find out the "true" end and start time for each start and end section using mid-day 12 as a judgement point. In other words, I have divided the time periods from 5 pairs to 10 unique time periods with its own start and end time.
To find Start time, enter the following formula in Cell J6 and drag it across;
=IF(LEFT(J3,5)="Start",J5,IF(J5<12,0,12))
To find End time, enter the following formula in Cell J7 and drag it across;
=IF(LEFT(J3,3)="End",J5,IF(J5>12,24,12))
An optional step, you can give a name to range J6:S6 as Start, and give a name to range J7:S7 as End, then you can enter the following formula in cell T5 to count the occurrences of each given starting time:
=SUMPRODUCT((T$1>=Start)*(T$1<=End))
EDIT#2
It is actually possible to combine the above into one array formula (so avoid using actual helper rows) which needs to be confirmed by pressing Ctrl+Shift+Enter upon finishing the formula in the formula bar.
=SUMPRODUCT((T$1>=IF(LEFT($J$3:$S$3,5)="Start",$J5:$S5,IF($J5:$S5<12,0,12)))*(T$1<=IF(LEFT($J$3:$S$3,3)="End",$J5:$S5,IF($J5:$S5>12,24,12))))
Enter the above in cell T5 and drag it across.
Let me know if you have any questions. Cheers :)
Excel's assumptions about cells are confusing the heck out of me. I'm on Office 365 - Excel for Mac, Version 15.28.
I'm TimeRecording on a lot of things, I would like to calculate relations and tendencies on the different things. I've exported my log-files, and have opened it in excel. A simple version looks like this:
In the real sheet, then I have 40+ tasks and 50+ dates. I would like to be able to do some calculations on these data. But Excel doesn't 'know what it is' (time durations) and therefore can't add them up or do anything.
So one question would be, to how to let Excel know, that this is time durations? I tried doing what this question suggests. But when I format the cells as [h]:mm then it gives me this error:
FYI: In the big sheet, then there's so many times, so the total amounts up to something along the lines of 633:33.
I would just like to be able to do simple calculations, such as:
=SUM(B1, C4, D5)
or
=SUM(B1, C4, D5)/COUNT(B1, C4, D5)
And maybe also make some charts and graphs.
Another attempt I've done is to try to get all the cells to have the format hh.mm instead of hh:mm, but this gave me problems. My approach was this:
Convert all the cells to 'Text' to tell Excel: 'Hey... Don't do any auto-converting/guessing here, and don't turn any of the cells into dates or decimal numbers or fricking origami swans!'
After that then I make a simple 'Replace all' of : to .
But after the 'Replace all', then 633:33 turns into 633.36.00 (even though the cell was a 'Text' cell).
And if I then simply double-click on the cell to edit it, then the numbers 'magically' turns from 633.36.00 to 27/01/1900 15.36.00 ... What the hell!? I need a procedure that doesn't require me to go through all my thousands of numbers and edit any of them (or ensure that Excel have turned the numbers into flying unicorns.
EDIT1
Here's an example of the total sheet I'm working on in Google Sheets.
EDIT2
If I format the cells as [h]:mm, then I get an error (see above). But if I format it as [t]:mm, then I don't get an error (thanks to Axel Richter for pointing that out). It may have something to do with the initial language of my Excel-installation (danish).
However... If I then try to sum up a bunch of cell, after doing this formatting to everything, then it sums up to 0:00.
If I format all the cells to Time (well-knowing that it's the wrong format, but hoping that Excel can see it and fix it) - and thereafter trying to sum up a couple of cells, then it sums up to 00.00.00 (even though it wasn't empty cells).
Is it also important, that when I sum up some numbers, that I do it from a General-cell - or does Excel know, that if I start with the =-sign, that it's going to be a calculation (and therefore the cell-format doesn't matter)?
Excel will store date-time values as floating point double values in following form:
1 day = 1
1 hour = 1/24 = 0.0416666666666667
1 minute = 1/24/60 = 0.000694444444444444
So formatted as time all values greater than or equal 0 but lower than 1 will be from 00:00 to 23:59. Values greater than 1 will be dates with 1 = 01/01/1900 00:00:00. But if you are formatting such values as time only using hh:mm for example, then only the time is shown. The date is simply hidden.
For example 1.25 formatted using hh:mm will show 06:00 although it is 1 1/4 day which is 01/01/1900 06:00:00. To see hours from multiple days the format [h]:mm can be used. For example 1.25 formatted using [h]:mm will show 30:00 which is 1 day (24:00) + 1/4 day (06:00).
Although Excel will do this independent of locale settings, the user defined format codes used and the kind of input values which Excel will take as time values are dependent of locale settings.
For example with your locale Danish (Greenland) the format codes are different. See Formatere tal som datoer eller klokkeslæt .
So your format code will be [t]:mm instead of [h]:mm.
And also with your locale Danish (Greenland) the time separator is . instead of :. So values which Excel will take as time values are 123.45 (123 hours, 45 minutes) instead of 123:45.
In your last comment you say: "whereafter it weirdly looked the same, such as: 123:45 and not 123.45". Yes that is because your user defined format [t]:mm contains the time separator : also. But that is different from your locale settings where . is the time separator. While inputting values Excel respects the locale settings and so expects 123.45 as time value for 123 hours and 45 minutes. But after the input Excel applies the cell formatting [t]:mm and so shows 123:45.
In your last comment you say that it confuses you that 17:24 * 24 equals 417:36. But that is exactly what it should.
17:24 is 17 hours and 24 minutes. That multiplied by 24 is 17 hours * 24 = 408 hours and 24 minutes * 24 = 576 minutes. 576 minutes are 9 hours and 36 minutes. So we get (408 hours + 9 hours) and 36 minutes = 417 hours and 36 minutes = 417:36.
I cannot edit the sheet so I copied it. As you can see in column AS and row 43, Google provides 'duration' format. You don't have to manipulate something. Just change the cell format.
In Excel, duration format is [h]:mm. Hit ctrl + 1 at the cell and choose Custom and type [h]:mm at Type and hit enter.
If SO answer is too difficult to follow, try this.
I apologize in advance for how rough this is, but I mostly slapped this code together to fit the task and didn't want to waste time on it. The principles are there though, so at the least it should point you in the direction you need to be heading.
Sub Time_Summarization()
Dim i As Long
Dim j As Long
Dim cell As Range
Dim sHolder As String
Dim vHolder As Variant
Dim arrHolder() As Double
Dim bAdd As Boolean
Dim dHolder_Whole As Double
Dim dHolder_Remainder As Double
Dim sOutput As String
ReDim arrHolder(0 To 2)
' Use a set range. Selection here is just for testing
' Ideally there should be data validation in this loop to ensure that the input
' values are numeric time values.
For Each cell In Selection
' Convert the cell value to a date to permit splitting.
' The value is then split into a 1-d array with 3 positions (H, M, S)
vHolder = Split(CDate(cell.value), ":")
' Loop through the split values from first to last, and trim off the AM/PM.
' If it is a PM date, set the flag to add 12 (13:00:00 gets displayed as 1:00:00 PM)
For j = LBound(vHolder) To UBound(vHolder)
' If PM, set the flag.
If InStr(vHolder(j), "PM") Then bAdd = True
' Remove "AM" and "PM"
vHolder(j) = Replace(vHolder(j), " AM", vbNullString)
vHolder(j) = Replace(vHolder(j), " PM", vbNullString)
' Add the values into the array in the same order.
arrHolder(j) = arrHolder(j) + vHolder(j)
Next
' Add 12 hours if needed
If bAdd Then arrHolder(0) = arrHolder(0) + 12
' Reset the flag for the next loop
bAdd = False
Next
' Step backwards through the array to round up increments of 60.
For i = UBound(arrHolder) To LBound(arrHolder) + 1 Step -1
' This will return the number of times the value goes into 60.
dHolder_Whole = arrHolder(i) \ 60
' This will return the remainder of the value divided by 60.
dHolder_Remainder = arrHolder(i) Mod 60
' Round up seconds to minutes, and minutes to hours.
arrHolder(i - 1) = arrHolder(i - 1) + dHolder_Whole
' Overwrite the remainder
arrHolder(i) = dHolder_Remainder
Next
' Combine the separate values into a string.
sHolder = arrHolder(0) & ":" & arrHolder(1) & ":" & arrHolder(2)
' Just for testing, do with the values whatever you wish.
Debug.Print sHolder
End Sub
Again, this is mostly a model that will work, but will need to be adapted to suit your needs.
Zeth, I downloaded your file and I can make some calculation with your time data. I juss selected all cell with time duration and change the format of cell to "time". Seemingly you should change all cells format, incluiding the empty cells.
If it does not work, find the "More format of numbers" ate the "Numbers" menu. Then, select the option "Hour" and chose the format closest to the format of your data. Also pay attenction to the option "locality" at the bottom of this menu. The option of hour format deppends on the region selected. (Each region in the world have some convenctions about it and Excel reconize much of then.
Formatting the numbers does not change the way Excel does calculations.
So a cell (c3) formatted as time and showing 01:28:00 actually contains 0.061111 because Excel treats time as fractions of a 24 hour day.
When you add up a lot of times and they add up to more than 24 hours the underlying number is more than 1 day so you get number of days before the decimal point and after the decimal point is the fraction of 24 hours remaining. So to convert a duration or time to hours you just multiply it by 24 and format it as a number or general (and the numbers after the decimal point are fractions of an hour). If you just want to format the result as hours and minutes use a format of [h]:mm and do not multiply by 24 - on your system look at Format Cells - Custom to see what the equivalent of [h:mm] is.
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...
I have a device which outputs the time in the format hh:mm:ss.000, e.g., 00:04:58.727 and I need to convert these to milliseconds.
I can't change the way the device outputs the times so I have to do it in Excel, but I don't know VB so am looking for a cell-by-cell solution.
Let's say that your time value is in cell A1 then in A2 you can put:
=A1*1000*60*60*24
or simply:
=A1*86400000
What I am doing is taking the decimal value of the time and multiply it by 1000 (milliseconds) and 60 (seconds) and 60 (minutes) and 24 (hours).
You will then need to format cell A2 as General for it to be in milliseconds format.
If your time is a text value then use:
=TIMEVALUE(A1)*86400000
UPDATE
Per #dandfra's comment this solution may not work in the Italian version of Excel.
Using some text manipulation we can separate each unit of time and then sum them together with their millisecond coefficients.
To show the formulas in the cells use CTRL + `
Use
=LEFT(B2, 2)*3600000 + MID(B2,4,2) * 60000 + MID(B2,7,2)*1000 + RIGHT(B2,3)
you can do it like this:
cell[B1]: 0:04:58.727
cell[B2]: =FIND(".";B1)
cell[B3]: =LEFT(B1;B2-7)
cell[B4]: =MID(B1;11-8;2)
cell[B5]: =RIGHT(B1;6)
cell[B6]: =B3*3600000+B4*60000+B5
maybe you have to multiply B5 also with 1000.
=FIND(".";B1) is only necessary because you might have inputs like '0:04:58.727' or '10:04:58.727' with different length.
Rather than doing string manipulation, you can use the HOUR, MINUTE, SECOND functions to break apart the time. You can then multiply by 60*60*1000, 60*1000, and 1000 respectively to get milliseconds.
Here it is as a single formula:
=(RIGHT(D2,3))+(MID(D2,7,2)*1000)+(MID(D2,4,2)*60000)+(LEFT(D2,2)*3600000)
try this:
=(RIGHT(E9;3))+(MID(E9;7;2)*1000)+(MID(E9;5;2)*3600000)+(LEFT(E9;2)*216000000)
Maybe you need to change semi-colon by coma...