How to convert DD:HH:MM to HH:MM in Excel - excel-formula

I am facing a problem with excel.How can I convert DD:HH:MM to HH:MM in excel?
Here is an exmaple showcasing what I need.
1:02:49(1day, 2hours, 49 mins) should come as 26:49(26 hours, 49 min)

I'm guessing that your 1:02:49 cell is formatted as text; otherwise, you could just change the cell format from DD:HH:MM to HH:MM.
I've opted to output as text, but could change it to an actual Time value if needbe.
Yes, the formula is a bit long but it can cope with any number of digits between each :. So, for example, 100:3:4 (100 days, 3 hours, 4 minutes) would correctly evaluate to 2403:04
=24*LEFT(A1,FIND(":",A1)-1)+MID(A1,FIND(":",A1)+1,LEN(A1)-2-LEN(RIGHT(A1,LEN(A1)-FIND("#",SUBSTITUTE(A1,":","#",2))))-LEN(LEFT(A1,FIND(":",A1)-1)))&":"&TEXT(RIGHT(A1,LEN(A1)-FIND("#",SUBSTITUTE(A1,":","#",2))),"00")

Related

Converting Non-Time String into HH:MM

I have a Cell range that contains data in the following format:
1d 12h 37m
All Data is in this format but ranges from single to double digit values.
I need to try to convert this data as an ultimate goal into purely hh:mm
I am struggling with the conversion of this. The main issue arises when the number of digits varying between double and single digits.
I have the formula to extrapolate purely the numbers and remove the letters from this:
=SUM(ROUND(MOD(SMALL(IFERROR(ROW(OFFSET(A$1,,,LEN(A11)))+MID(A11,1+LEN(A11)-ROW(OFFSET(A$1,,,LEN(A11))),1)%, LEN(A11)+1), ROW(OFFSET(A$1,,,SUM(N(ISNUMBER(0+MID(A11,ROW(OFFSET(A$1,,,LEN(A11))),1))))))),1)*100,0)*(10^(ROW(OFFSET(A$1,,,SUM(N(ISNUMBER(0+MID(A11,ROW(OFFSET(A$1,,,LEN(A11))),1))))))-1)))&""
Ideally this needs to all be done as a formula but a VBA script is okay.
Any ideas?
You can use this formula to change to date/time:
=IFERROR(LEFT(A1,FIND("d",A1)-1),0)+TRIM(SUBSTITUTE(SUBSTITUTE(MID(A1,IFERROR(FIND("d",A1)+1,1),LEN(A1)),"h ",":"),"m",""))
Then either format it [hh]:mm which will return 36:37 or hh:mm which will return 12:37
=TEXT(((LEFT(A2,FIND("d",A2)-1))+((TRIM(MID(A2,FIND("d",A2)+1,FIND("h",A2)-FIND("d",A2)-1)))+((TRIM(MID(A2,FIND("h",A2)+1,FIND("m",A2)-FIND("h",A2)-1)))/60))/24),"[h]:mm")
This formula assumes a couple things:
"d", "h", "m" will always be present
You need Days converted to Hours
Explanation:
Days:
=(LEFT(A2,FIND("d",A2)-1))
Hours:
=(TRIM(MID(A2,FIND("d",A2)+1,FIND("h",A2)-FIND("d",A2)-1)))
Minutes:
=(TRIM(MID(A2,FIND("h",A2)+1,FIND("m",A2)-FIND("h",A2)-1)))
Combining:
=TEXT((<days>+(<hours>+(<minutes>/60))/24),"[h]:mm")
If you want it without Days converted to Hours, change "[h]:mm" to "hh:mm".

Multiple custome date format for one column?

Can we put up a OR command for custom time in one column?
I have multiple time formats in one column of excel. For eg:
Timing
30 min
31 sec
4 min 20 sec
1 hr 2 min
3 hr
1 hr 23 min 30 sec
I want to convert it to time format: hh:mm:ss so that i can calculate average from all times. How can I achieve it?
Here's a shorter formula:
=TIME(IF(IFERROR(FIND("hr";$A2);0)=0;0;IFERROR(MID($A2;IFERROR(FIND("hr";$A2);0)-3;2);MID($A2;IFERROR(FIND("hr";$A2);0)-2;1)));IF(IFERROR(FIND("min";$A2);0)=0;0;IFERROR(MID($A2;IFERROR(FIND("min";$A2);0)-3;2);MID($A2;IFERROR(FIND("min";$A2);0)-2;1)));IF(IFERROR(FIND("sec";$A2);0)=0;0;IFERROR(MID($A2;IFERROR(FIND("sec";$A2);0)-3;2);MID($A2;IFERROR(FIND("sec";$A2);0)-2;1))))
Note: the above formula contains semicolon (;) as a separator. Replace with coma (,), in case this is your system separator.
To be honest I did not try to decipher #Foxfire's formula.
Remember to apply custom time format to the result cell: [h]:mm:ss
For explanatory reasons see breakdown of the long formula:
This huge formula worked for me:
=IF(AND(IFERROR(FIND("hr";A1;1);0)>0;IFERROR(FIND("min";A1;1);0)>0;IFERROR(FIND("sec";A1;1);0)>0);TEXT(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1;" ";"");"hr";":");"min";":");"sec";"");"hh:mm:ss");IF(AND(IFERROR(FIND("hr";A1;1);0)>0;IFERROR(FIND("min";A1;1);0)>0;IFERROR(FIND("sec";A1;1);0)=0);TEXT(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(TRIM(A1)&" 00 sec";" ";"");"hr";":");"min";":");"sec";"");"hh:mm:ss");IF(AND(IFERROR(FIND("hr";A1;1);0)=0;IFERROR(FIND("min";A1;1);0)>0;IFERROR(FIND("sec";A1;1);0)>0);TEXT(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE("00 hr " & TRIM(A1);" ";"");"hr";":");"min";":");"sec";"");"hh:mm:ss");IF(AND(IFERROR(FIND("hr";A1;1);0)>0;IFERROR(FIND("min";A1;1);0)=0;IFERROR(FIND("sec";A1;1);0)=0);TEXT(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(TRIM(A1)&"00 min 00 sec";" ";"");"hr";":");"min";":");"sec";"");"hh:mm:ss");IF(AND(IFERROR(FIND("hr";A1;1);0)=0;IFERROR(FIND("min";A1;1);0)>0;IFERROR(FIND("sec";A1;1);0)=0);TEXT(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE("00 hr " & TRIM(A1)&" 00 sec";" ";"");"hr";":");"min";":");"sec";"");"hh:mm:ss");IF(AND(IFERROR(FIND("hr";A1;1);0)=0;IFERROR(FIND("min";A1;1);0)=0;IFERROR(FIND("sec";A1;1);0)>0);TEXT(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE("00 hr 00 min "&TRIM(A1);" ";"");"hr";":");"min";":");"sec";"");"hh:mm:ss");"Formula needs to be updated"))))))
As I said, you need to check every string in your text. Depending if it contains hr,min,sec, you need to calculate the time and then convert it to time. Also, you need to take care of those annoying blanks at end of some strings. This formula does all this.
Hope you can adapt this to your needs. My Excel is in spanish, but I translated formulas manually. Just in case I typed wrong, I uploaded a file example to Gdrive for you to download and check the formulas (they should autotranslate if you open it).
https://drive.google.com/open?id=13J5IWLOFFZpzvIp1oqPwqkE3eHDk7EeH

Convert hh:mm:ss to decimal days

I am having the worst time trying to find what seems to be a simple formula. I want to convert hh:mm:ss into days with a decimal rounded to tenths of a day.
36:00:00 result = 1.5 days
49:32:28 result = 2.1 days
Every format I try turns into some odd value.
You could use VALUE. And if you want to ignore blanks (which would result in 0), then wrap it into an IF like this:
=IF(A1="", "", VALUE(A1))

How to convert long minutes to hours in excel

I need a formula in excel to convert minutes to hours. Until now came the following formula:
=A1/1440
So, 180minutes its converted to 03:00, when formatted as hh:mm
But, i need also to convert long minutes, like 1600. In this case, the formula converts to 02:40, when it should show 26:40.
Any ideas?
You can try
=INT(A1/60)&":" &MOD(A1,60)
and =TEXT(FLOOR(A1/60,1),"00")&":"&TEXT(MOD(A1,60),"00") for Format hh:mm
Use exactly the same formula you are using now, but change the display format to:
[h]:mm:ss
That will display in the format you want AND allow you to perform operations on the values.
( With format showing in the top of the time columns)
[h]:mm:ss hh:mm:ss Equal?
=1600/1440 =1600/1440 =G23=F23
=F23+1600/1440 =G23+1600/1440 =G24=F24
Gives
[h]:mm:ss hh:mm:ss Equal?
26:40:00 2:40:00 TRUE
53:20:00 5:20:00 TRUE

Hours Calculations in Excel 2010

I have an Excel 2010 workbook which contains a cell with the value of, say, 9876:54:32 (manually entered) representing 9876 hours, 54 minutes and 32 seconds of, say, phone talk time.
Then I have a cell with the value of, say, 1000 (manually entered) representing 1000 calls.
I want to divide the values to get the average talk time of 592.615 minutes per call.
I'm doing a regular =A1/B1 and it gives me an error.
* EDITED *
Thanks Brain Webster for correcting my math. I mean 9.876 hours. But the point is that Excel gives me an error, not my manual math. Playing around with it I discovered that Excel is fine with me with values up to 9999:59:59. Once I try with 10000:00:00 and up, it doesn't recognize it as a time value.
I love these seemingly easy riddles, so here is my solution as a formula and as a VBA attempt:
my original:
= (LINKS(A38;FINDEN(":";A38)-1)/24)+ZEITWERT("0"&RECHTS(A38;LĂ„NGE(A38)-FINDEN(":";A38)+1))
translated:
= (LEFT(A38,FIND(":",A38)-1)/24)+TIMEVALUE("0"&RIGHT(A38,LEN(A38)-FIND(":",A38)+1))
This will get you the right value to a given 10k text of a time duration. You would only have to setup the format of the cell to [h]:mm:ss. Then those values will look the same, but one would be a string and the other a number - and that is a major difference ;)
In vba it looks much more easier, and once defined, you can use it as a worksheetfunction.
Public Function GetDurationValue(ByVal strInput As String) As Double
Dim arrResult As Variant
arrResult = Split(strInput, ":") 'saves you parsing
GetDurationValue = (arrResult(0) / 24) + _
TimeSerial(0, arrResult(1), arrResult(2))
End Function
A38 = "10971:12:14"
=GetDurationValue(A38)
=457.13349537037
You can use LEFT and RIGHT function to retreive parts of the time value and then sum and multiply these values by 60 [minutes] (resp. 3600 [hours]).
Something like this for the hours, minutes, seconds (A1 is the cell with time value):
B1=VALUE(LEFT(A1;FIND(":";A1)))*3600
B2=VALUE(LEFT(A1;FIND(":";A1; FIND(":";A1))))*60
B3=VALUE(LEFT(A1;FIND(":";A1; FIND(":";A1; FIND(":";A1)))))
Now you can sum that:
C1=SUM(B1;B2;B3)
Then divede by calls count (A2 is the cell with the calls count):
D1=C1/A2
Finally format it like time:
E1=TEXT(D1/(24*3600);"d \day\s hh:mm:ss")
BTW: I tried that in Excel 2013 and when I enter 111:22:33 into a cell it automatically converts to a time. So then I can divide it like you try...
It appears that hours > 10000 are not recognised as such by Excel. Therefore we need to introduce an IF() to see whether this is the case and determined the alternative formula for the case where hours >10000
=IF(ISERROR(FIND(":",A2)),A2/B2, <SCRIPT IN CASE OF >10000>)
<SCRIPT IN CASE OF >10000> will now be:
VALUE(LEFT(A2,FIND(":",A2)))/24+VALUE(LEFT(A2,FIND(":",A2, FIND(":",A2))))/(24*60)+VALUE(LEFT(A2,FIND(":",A2, FIND(":",A2,FIND(":",A2)))))*(24*60*60)
combine and enjoy!
Assuming you don't exceed 100,000 hours in A1, and you always display hours, minutes and seconds then this formula should suffice
=IFERROR(A1/B1,(LEFT(A1)*10000/24+RIGHT(A1,10))/B1)
format result cell as [h]:mm:ss to get the result as a time value
With 10971:12:14 in A1 and 1000 in B1 that should give a result of 10:58:16 [or format result cell as [m]:ss to get minutes and seconds like 658:16]
This version will work with any number of hours and with or without seconds
=IFERROR(A1/B1,(LEFT(A1,FIND(":",A1)-1)/24+RIGHT(A1&IF(COUNTIF(A1,":*:"),"",":00"),5)/60)/B1)

Resources