Left , Right function - excel-formula

I am trying to convert a time format 3:45 into decimal, I can get the left and right parts separately using left(text(T,"hh:mm"),2) and right(text(T,"hh:mm"),2)/60 but when I try to add he two together I just get 00:00 or a whole number. I know there may be other ways of soling the problem but I'd like to get to the bottom of what I'm doing wrong.

Convert time value to text with a decimal point in between and then to a value, VALUE(TEXT(A1,"hh.mm"))

Normally, if the cell contains a time value, it is already a numerical type. You can verify this by doing =ISNUMBER( T ) and if it is TRUE, then you already have a numerical value and only need to convert it to the unit measure that you want it to be. It looks like you want the result in fractional hours, so you can simply do:
=T*24
All time values are measured in days, so you are simply multiplying it by 24 to convert it to hours.
If it turns out the your cell is text (i.e. =ISNUMBER( T ) is FALSE), then you can convert it to a time value with the TIMEVALUE function =TIMEVALUE( T ). Then, likewise, you can convert that to hours like this:
=TIMEVALUE(T)*24

Related

Calculate time difference in milliseconds from a value i got using a formula in excel

So I'm using the MID value to get the time out of the string, since my excel is in German the command is:
=TEIL(A2;11;13)
from
2022-09-08 11:50:16,765 INFO
Which leaves me with
11:50:16,765
I get the second time value in the same way. I have tried splitting the seconds and milliseconds by both . [DOTS] & , [COMMAS].
After I want to calculate the time difference I subtract the higher value (second time) from the lower one (first time), although my result is
#WERT! (#VALUE!).
I have looked up for solutions already and figured out that for the German region I should use the time format hh:mm:ss,000 instead of hh:mm:ss.000 [COMMA instead of DOT]. Used this in all 3 cells (B2, C2 & D2 etc.).
Since it didn't work, I´ve tried to simply write some values in milliseconds as a text and divide them using the German time format and it worked (see columns E & F).
So my conclusion is that I am not able to subtract the values from each other because I am getting them from a formula? (Please correct me if I am wrong).
By using 11;13 in you mid you are capturing the leading space and this is causing Excel not to be able to convert the string to a true time.
Either TRIM the results in the subtraction:
=TRIM(C2)-TRIM(B2)
Or better yet, grab just the numbers without the spaces:
=MID(A2,12,12)
or in German:
=TEIL(A2;12;12)

MS-EXCEL: time averages + numbers to time

I am working on a project for my work and I am having an issue trying to take times and averaging them out. I am getting a #DIV/0! When I convert the cells to XX:XX.
Below are screen shots of the same data and function. The top is with regular numbers the bottom is where I formatted all cells to display in time XX:XX.
Numbers (works fine)
= AVERAGE(H29,J29,P29,V29,AE29,AJ29)
Time (XX:XX) however I get the #DIV/0!. The AVERAGE Function I am using looks like this:
=AVERAGE(H29,J29,P29,V29,AE29,AJ29)
Also, if possible, could I enter the data in regular numbers (not time) then have it display in average time (hours:min) on the right?.
Thank you.
When working in Excel with dates and times always leave the value as a number and apply formatting. where you have tried to enter a time in hh:mm, you need to show the hours even if they are blank, or the value of that cell becomes a string. But you can't average a string.
These are valid entries 00:23 or 0:23
:23 is not valid time, so is treated as a string
Valid times are stored as a number where 24 hours = 1.
Times are stored as a fraction for example 0:45 = 0.031250000
To fix it, add in the missing leading zeros, or if you have explicitly entered text strings: type a 1 in any cell and copy it, then select all of your time cells and do paste special multiply. That will convert them back to numbers and your average should work. Then apply your custom formatting of required .
I would suggest that users enter the time in minutes eg 17, 23, 92 and you average these, but for the conversion I suggest that you use a formula like this:
=AVERAGE(H29,J29,P29,V29,AE29,AJ29)/(24*60)
This will convert the average time in minutes, into a fraction of a day.
You can then put custom formatting onto the cell to change the format to hh:mm

Using this value "2016-05-12 21:51:13 -0500" in Excel

How do I work with a Date Time -0500 value?
I have a sheet that has a value that looks like this:
2016-05-12 21:51:13 -0500
I want to be about to use it.
I want to filter all records that are greater than
2016-05-12 00:00:01 -0500
But I do not know how to work with this value.
Use this formula:
=--LEFT(A1,LEN(A1)-5)
Then format it like this
yyyy-mm-dd hh:mm:ss -\0\5\0\0
Then you can copy and paste the values and formatting where you want it
You need to convert the data into Excel date/times. With data in A1 in B1 enter:
=DATE(LEFT(A1,4),MID(A1,6,2),MID(A1,9,2))+TIME(MID(A1,12,2),MID(A1,15,2),MID(A1,18,2))
and format to display both date and time:
Let's presume for a moment that for some unknown reason Excel could not identify your string as a valid date time. You can always go back to basics and break your string down into its components. Let's start off and assume that your date time and offset string are in cell A1.
Step 1) Strip out the year
=left(A1,4)
Step 2) Strip out the month
=MID(A1,FIND("-",A1)+1,FIND("-",A1,FIND("-",A1)+1)-FIND("-",A1)-1)
That bad boy of a formula looks for the first - and the second - and based on that information finds the starting position to start pulling characters from and figures out how many characters to pull.
In your case we could have set it to pull two characters and had it start at character six as there is no variation to your date format. However, in a generic sense where there are not always leading zeros in the month, or sometimes you were flipping between four characters for the year and two characters for the year, the above would still work.
I am also assuming that month is the middle value (05) and you are not talking about December 5th here.
Step 3) Pull out the day
We could have used a similar approach using mid here, and again we could have hard coded it (wait, I did hard code two character return). Instead for a little flavour I used a right left sequence.
=RIGHT(LEFT(A1,FIND(" ",A1)-1),2)
Step 4) Pull out the time
Now you could go through the whole process and pull out hours, minutes and seconds, but Excel is usually pretty good at recognizing a time format as there is not much variation to it. Also this gives an opportunity to see a new formula for dealing with string manipulation.
Now since your time format was constant, I got a little lazy knowing that your time was always going to be eight characters long since your format always has a leading zero. As such, I used the following:
=TIMEVALUE(MID(A1,FIND(" ",A1)+1,8))
Basically, I grabbed the whole time, HH:mm:ss, and dumped it into timevalue (note there is also a datevalue). Timevalue will attempt to convert a string in time format to Excel time format as a decimal value.
Now as previously noted, if all those times are all stamped with the same -0500, just ignore it.
To get all that date and time converted into a single cell we would take each of the date parts and drop them into the DATE function and then add the time component on. In Excel speak that looks like:
=DATE(LEFT(A1,4),MID(A1,FIND("-",A1)+1,FIND("-",A1,FIND("-",A1)+1)-FIND("-",A1)-1),RIGHT(LEFT(A1,FIND(" ",A1)-1),2))+TIMEVALUE(MID(A1,FIND(" ",A1)+1,8))
Now if you want that to display with the -0500, look at Scott's answer for formatting. If you want to convert the time to local time and get rid of the -0500 then you would need to add -5 hours to the above formula which would look something like:
=DATE(LEFT(A1,4),MID(A1,FIND("-",A1)+1,FIND("-",A1,FIND("-",A1)+1)-FIND("-",A1)-1),RIGHT(LEFT(A1,FIND(" ",A1)-1),2))+TIMEVALUE(MID(A1,FIND(" ",A1)+1,8))+time(-5,0,0)
And if we were not so lazy and did not want to hard code the time, it would look more like:
=DATE(LEFT(A1,4),MID(A1,FIND("-",A1)+1,FIND("-",A1,FIND("-",A1)+1)-FIND("-",A1)-1),RIGHT(LEFT(A1,FIND(" ",A1)-1),2))+TIMEVALUE(MID(A1,FIND(" ",A1)+1,8))+TIME(LEFT(RIGHT(A1,4),2),RIGHT(A1,2),0)*IF(LEFT(RIGHT(A1,5),1)="-",-1,1)

Excel: Converting From Integer Parts Time To Minutes Time

I have some columns where the date values are in integer format, i.e.14.06736111
for 1:37. I want to get the format into minutes.
I tried using the [m[ format in custom format, and that works on many of the cells, but some of them throw out crazy numbers. For example, for the cell where the time is 1:37 I am getting 20257 instead of 97. It looks like the cells that have wacky values also have a nonsense date string attached (1/14/1900).
I can use find/replace to remove the date string and the the format works again, but that seems inefficient.
Is there a better way around this?
Your 14.06736111 is not a time; it's a date (01/14/1900) with a time (.06736111 of a 24-hour period). I'm guessing that the date portion is incorrect, or you're not actually seeing a date value at all.
To display just the time, your cell first needs to remove the integer part of the date (the part to the left of the decimal point). If your date value is in cell A1 as 14.06736111:
=A1-Int(A1)
#nutsch points out in a comment below that a shorter means of doing this would be
=MOD(A1, 1)
Set the cell formatting to Time:
1:37:00AM
Using =A1-Int(A1) as suggested by Ken White helped a lot, but I was still having problems. Through a bit of trial and error I found that the best way to convert an fractal time value into whole minutes was to use the following formula:
=FLOOR(A1/0.000694, 1)

EXCEL - Substract two 24hr time format cells with seconds and miliseconds

Okay, so I have two cells:
Start End
11:31:37.644 11:31:51.269
I'd like to subtract the two and return the remaining time which should equal something around 14 seconds.
Edit for more information:
My values I'm inputting are like so:
113137.644
113151.269
and I have a custom formatter set to: 00\:00\:00.000 to display what you see at the very top.
It would be better if you could input the values as real time values then you can just use a simple subtraction
=A2-A1
...but with the values as they are you can do a conversion and subtraction all in one using TEXT function, e.g. in A3 use this formula
=TEXT(A2,"00\:00\:00.000")-TEXT(A1,"00\:00\:00.000")
format A3 as [h]:mm:ss.000 to get 0:00:13.625 for your example
Assumes times are on the same "day", if you need to pass midnight you can revise formula to
=MOD(TEXT(A2,"00\:00\:00.000")-TEXT(A1,"00\:00\:00.000"),1)
You need to use the MID function to grab each section of the time, like this:
=MID(A1,1,2)&":"&MID(A1,3,2)&":"&MID(A1,5,2)&"."&MID(A1,8,3)
This will change 113137.644 to 11:31:37.644.
You can then do the math on it like this (all in one cell, but broken up here for readability):
=TEXT(MID(B1,1,2)&":"&MID(B1,3,2)&":"&MID(B1,5,2)&"."&MID(B1,8,3), "hh:mm:ss.000")
-
TEXT(MID(A1,1,2)&":"&MID(A1,3,2)&":"&MID(A1,5,2)&"."&MID(A1,8,3),"hh:mm:ss.000")
That should give you 0.000157697. Change the field's custom format to hh:mm:ss.000 to give you 00:00:13.625.
You can use this formula to convert your values to time
=(LEFT(A1,2)+(MID(A1,3,2)+RIGHT(A1,LEN(A1)-4)/60)/60)/24
You can then subtract and convert back using the following formula
=TEXT(B1,"hhmm")&TEXT(MOD(B1*24*60,1)*60,"00.000")
But it would probably be better for you to actually use proper decimal values in fractions of days or hours rather than this you can't calculate anything with.

Resources