Time comparison in Excel - excel

This should be straight-forward, I'm trying to compare if a value of time is less (or more) than another.
=IF(A1 > B1,True,False)
Where A1 and B1 are a number of hours and minutes in [h]:mm format.
A1 is 48:45 in [h]:mm format
B1 is 50:00 in [h]:mm format
If I wanted to replace B1, in the formula, with an absolute time (say of fifty hours) than I thought the answer might be either:
=IF(A1 > TEXT("50:00", "[h]:mm"),True,False)
=IF(A1 > TIME(50,00,0),True,False)
But it's not. Any ideas?

TEXT returns Text and not a number and as such it would always be greater than the time.
But we can turn it into a number by simple multiplying it by -1*-1
=A1>--TEXT("50:00", "[h]:mm")
But then the simple would also work:
=A1>--"50:00"
TIME returns the time portion and as such:
TIME(50,00,0)
resolves to 2:00 or 0.0833333 as it is the time part of the number without the integer.
So we can just do some simple math:
=A1 > 50/24
now the 50/24 will resolve properly to 2.083333

The VALUE function can come in handy for you. It's the build-in function to turn text-strings that represent a numeric value into an actual numeric value, so:
=A1>VALUE("50:00")

Related

Finding the difference in time in excel

Hopefully this is a better phrased question... Ultimately what I'm trying to do is figure out if someone is late or not. So I have their shift start times... it's in a string format of XXX-####, e.i. Sun-0320. I also have a timestamp(Macro) of when they clocked in same format as Now()
So currently I have it as
A1 = Now()
B1 = Right(F1,4)
F1 = ShiftCode
C1 = A1-B1
A1 and B1 are both formatted to custom time of hh:mm
C1 is formatted as numbers. i tried time also
The NOW() function returns both the date and time, which changes as your cell/worksheet/workbook is being updated.
https://support.microsoft.com/en-us/office/now-function-3337fd29-145a-4347-b2e6-20c904739c46
There is a lot of options to add or subtract the time in excel, like here:
https://superuser.com/questions/89045/how-to-get-time-difference-as-minutes-in-excel
https://support.microsoft.com/en-us/office/calculate-the-difference-between-two-times-e1c78778-749b-49a3-b13e-737715505ff6
https://www.ablebits.com/office-addins-blog/2015/06/24/calculate-time-excel/
https://www.excel-easy.com/examples/time-difference.html
https://exceljet.net/formula/calculate-number-of-hours-between-two-times
but regarding your case I would rather use something like this:
instead of
=NOW()
expand the formula, by adding another TEXT function and defining the time units for it:
=TEXT(NOW(),"hh:mm:ss")
Then if you have another cell with a time value, you can easily add or subtract from the cell defined by the aforementioned formula.

Finding Random Time between given range using Randbetween function in Excel

I wish to find a Random Time between a given Time range containing Time format HH MM SS using a Randbetween function from excel. I just google around and came to know below function helps to get the result i need. but i need an explanation as i dint understand how this formula works. eg i dont know why it use 0 here and multiply and divide by 1000
=(RANDBETWEEN(0,($B$14-$A$14)*10000)/10000)+$A$14
B14 is ending time eg: 8:30
A14 is starting time eg: 7:30
Say we have two genuine times like:
9:15:23 AMand2:34:21 PM
If we first convert both times into integer seconds, we can use RANDBETWEEN(). Place the values in A1 and A2
then in B1 enter:
=A1*24*60*60
and copy downward.
In C1 enter:
=randbetween(b1,b2)/86400
and format as time:

change hh:mm into decimal hh.mm (see example)

In cell B239, I have 37:15 which represent the total number of hours it took someone to complete a task.
In cell C239 I have the following formula
=INT(B239)*24+HOUR(B239)+ROUND(MINUTE(B239)/60,2)
which gives me 37.25 that is 37 hours and a quarter of 100. I am happy with this result and it does what I am looking for. However, in B241 I have 24:00 which should technically return 24.00 but it returns 0 in cell C241 instead.
It is as if 24:00 is recognised as midnight rather than 24 hours.
Note that the format of B239 and C239 is [h]:mm. B241 and C241 format is general.
Many thanks for your assistance
Abe
Try this:
=TEXT(B239*24,"00.00")
on 24:00 it will return 24.00
As # Darren Bartrup-Cook mentioned this will be a text field so any reference using this needs to convert it to a number. There are many ways to do this.
You can us the double negative on the result, lets assume the result of the above formula is in C239:
=--C239
But ultimately the best method to do what you want is to format the cell in which you want the value as "General" with two decimal places then the whole thing can be done with one formula:
=Round(B239 * 24,2)
This will return a number and not a text with the correct formatting.

Meaning of two minus signs together ("double unary")

What does the two - sign mean at the beginning of a formula?
Ex:
This formula gets a string date and converts it into an Excel date serial number:
=--(MID(S2,4,3)&LEFT(S2,3)&MID(S2,7,4))
The formula works fine, I just want to understand the -- in the formula.
#JNevill's Comment seems a good answer to me but for the sake of an Answer consider Y in A1 and Y in B1. This formula:
=(A1=B1)
returns TRUE. As mentioned, stick an operator in front (with 0+, or 1*) and the Boolean is turned into 1, or 0 if B1 (only) is changed to, say, X.
The single minus negates that. 0-, or -1*, at the front returns -1 for both A1 and B1 equal to Y. Negate that and the -1 result becomes 1, say with =--1*(A1=B1).
But then multiplying by one (or adding zero) is pointless, might as well just go for:
=--(A1=B1)
Note that because of the order in which the evaluations take place, the above is not the same as:
=--A1=B1
which has no meaning so returns #VALUE!.
Text functions (MID and LEFT in your example) return strings, so constructing a date index for today for example (42311 in the 1900 date system) with such functions (alone) returns five characters Excel does not recognise as possibly representing a date. Converted to numeric format and represented as a date this should look like 'today'.
So format a cell as Text and enter 42311, then reformat as Date and the result is still 42311. Format a cell as General and enter:
=--("42"&"311")
before then formatting as Date and you should see something that looks like 'today'.

Converting MM:SS.ms to seconds using MS excel

I am looking for a neat way of converting a cell from
Minutes:Seconds.Milliseconds to
Seconds.Milliseconds
i.e.
11.111 = 11.111
1:11.111 = 71.111
I have something in place at the moment but its a bit hacky and I am sure there must be some nice excel feature to do this for me :P
Thanks!
Do this:
Place values 0:0:11.111 and 0:1:11.111 in cells B3 and B4 respectively.
Now format it to account for the milliseconds... Select cells B3 and B4, right click and choose Format Cells. In Custom, put the following in the text box labeled Type:
[h]:mm:ss.000
Now on cell C3 put the following formula:
=B3*86400
Fill C4 with the same formula...
Format column C as Number with 3 decimal places.
You're done! :)
Here's a screenshot of the attempt I made and that worked:
Edit:
As you wanna enter only MM:SS.ms you can format the entire B column with a custom format like: mm:ss.000. Now you can enter values as 02:11.111 and it'll convert it accordingly giving you 131.110. Hope it helps.
say your time is in cell A1, place this formula in B1
=IF(LEN(A1)>5,VALUE(TEXT(A1,"[ss].00")),A1)
If the time is less than a minute it outputs the time unaltered, greater than 1 minute it converts it to seconds & milliseconds (2 decimal places).
This will only work if your time in A1 is 10 seconds or greater.

Resources