Converting MMM:SS format into HH:MM:SS - excel

I have a user input which is given in the form MMM:SS e.g. 103:23 which I want to convert into a normal time format i.e. for the previous example 103:23 would be 01:43:23. Is it possible to do this using an excel formula?

This formula should do it, change A2 to reference the cell then input is in
=TIME(0,LEFT(A2,SEARCH(":",A2)-1),MID(A2,SEARCH(":",A2)+1,LEN(A2)))

This can be done simply by using the formula below where cell C5 is your input time
=TEXT(CONVERT(C5,"min","hr"),"hh:mm:ss")
Sample

If the input in cell A1 is text:
This formula returns a decimal number representing the time:
= TIMEVALUE( "00:" & A1 ) 'Change the `NumberFormat` to: `"HH:MM:SS"`
This formula returns a text representation of the time:
=TEXT(TIMEVALUE( "00:" & A1),"HH:MM:SS")
If the input in cell A1 is a number, it means that the NumberFormat of cell A1 is [mm]:ss:
This formula returns a decimal number representing the time:
= A1 'Change the `NumberFormat` to: `"HH:MM:SS"`
This formula returns a text representation of the time:
=TEXT( A1, "HH:MM:SS" )

in my case I have a limited max time limit so I was able to just write the following based on all of your inputs above. If anyone has any optimization suggestions for the code please feel free to share but this seems to work for the inputs that I have tried.
=IF(E3>=420,CONCATENATE("07:",(TEXT((LEFT(E3,3)-420),"00")),":",RIGHT(TEXT(E3,"0.00"),2)),
IF(E3>=360,CONCATENATE("06:",(TEXT((LEFT(E3,3)-360),"00")),":",RIGHT(TEXT(E3,"0.00"),2)),
IF(E3>=300,CONCATENATE("05:",(TEXT((LEFT(E3,3)-300),"00")),":",RIGHT(TEXT(E3,"0.00"),2)),
IF(E3>=240,CONCATENATE("04:",(TEXT((LEFT(E3,3)-240),"00")),":",RIGHT(TEXT(E3,"0.00"),2)),
IF(E3>=180,CONCATENATE("03:",(TEXT((LEFT(E3,3)-180),"00")),":",RIGHT(TEXT(E3,"0.00"),2)),
IF(E3>=120,CONCATENATE("02:",(TEXT((LEFT(E3,3)-120),"00")),":",RIGHT(TEXT(E3,"0.00"),2)),
IF(E3<60,CONCATENATE("00:",(TEXT(LEFT(E3,2),"00")),":",RIGHT(TEXT(E3,"0.00"),2)),
IF(E3>=60,CONCATENATE("01:",(TEXT((LEFT(E3,3)-60),"00")),":",RIGHT(TEXT(E3,"0.00"),2)),
))))))))

Related

Using MONTH() in a cell formula converts the cell type to "Custom" date format

I have a cell that has the formula =INDIRECT(CHAR(COLUMN()+65)&ROW())*MONTH($A$1)/12 where INDIRECT references an integer and $A$1 is a date. For some reason, the MONTH part converts the entire cell into a date instead of a number. How do I change the formula to have it return a number in number format? (Manually changing each cell through the ribbon is not an option for me).
I haven't tested this (and I can't comment till I get 50 rep), but you could wrap the whole thing in a text formula, then multiply by 1:
=TEXT(INDIRECT(CHAR(COLUMN()+65)&ROW())*MONTH($A$1)/12,"#")*1
Hope this helps!

Need to convert a specific text format to date format MM/DD/YYYY

I have an export from Active Directory of user accounts in a .csv/Excel where the date created cell is of General format (text?) as follows:
20150903075605.0Z in cell A1 which I need to convert to Date format as MM/DD/YYYY. I believe the text translates into 2015/09/03 but I could be wrong.
What I have tried so far:
Remove the .0Z and it changes to 2.01509E+ 13. Then in the
neighboring cell (B1) I try =DATE(A1) which gives me a #VALUE
Tried =DATE(LEFT(C2,2)+100,MID(C2,3,2),RIGHT(C2,2)) but that gives me
an obscure date of 4/12/2020.
This formula coverts the value in A1 into a true number:
=DATE(LEFT(A1,4),MID(A1,5,2),MID(A1,7,2))
You should apply number formatting to the cells where the formula is used. The number formatting would be: mm/dd/yyyy. In Excel, number formatting is often the best way to deal with dates.
If you need text instead of a true date, then:
=MID(A1,5,2)&"/"&MID(A1,7,2)&"/"&LEFT(A1,4)
let's say that 20150903075605.0Z is contained in cell A1, then you can get the MM/DD/YYYY date format by the following concatenation:
mid(A1, 5, 2) & "/" & mid(A1, 7, 2) & "/" & left(A1, 4)
So here is what I did to fix this. First strip the .0Z out.
Cell A2: 20040330191012 converting this to date (MM/DD/YYYY) in B2 by typing in =DATE(MID(C2,1,4),MID(C2,5,2),MID(C2,7,2)) gives me 3/30/2004.
I am pretty sure this is correct but if one of you guru's can confirm, it would be deeply appreciated.

excel formula to combine 2 cells into 1 in specific format

I have 2 cells, one cell has just text A1 cell, text (hello) other cell B1 has a timestamp (3:55). I need to combine these cell to one with this format: hello#t=3m55s, or if timastamp is 1:12:11 format will be hello#t=1h12m11s. So cell A1 will change to this specific format base on B1 cell.
Thank you.
You could try this formula:
=A1&"#t="&IF(HOUR(B1)=0,"",HOUR(B1)&"h")&MINUTE(B1)&"m"&SECOND(B1)&"s"
The & concatenates each part together. However, if the timestamps are not correct for the mm:ss times, then it won't work.
EDIT: To deal with the issue of timestamps:
=A1&"#t="&IF(SECOND(B1)<>0,HOUR(B1)&"h"&MINUTE(B1)&"m"&SECOND(B1)&"s", HOUR(B1)&"m"&MINUTE(B1)&"s")
The issue with this is that it won't work for timestamps of the type "11:11:00" But I don't think there's much to be done, unless the string is first converted to text, which I could give some pointers on.

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.

Have formula treat value as text, not numeric

I have an Excel formula reading data from a column. The data in that column is sometimes a date-like format, such as "10-11". Despite the fact that I've ensured that column is text formatted -- and all values display correctly as plain text, not reinterpreted as dates -- the formula is basically reinterpreting them as dates in the reference.
I need a way to force the formula's cell reference to interpret the cell as text. I tried TEXT(A1, "#") but it doesn't work -- it gives the numeric value of the date.
Brian Camire's answer explains why, but here's a worksheet function that will work for you. Note that you have to create that numeric array in it based on how long the longest string will be. It's an array formula, so when you first enter it you have to hit CTRL-SHIFT-ENTER, then you can click and drag it down the column.
=LEFT(A1, MATCH(FALSE, ISNUMBER(VALUE(MID(A1, {1,2,3,4,5}, 1))),0) - 1)
Short answer: When referring to number-like (or date-like) text values in a formula, don't use them in a place in the formula where Excel is expecting a number.
Long answer: Even if the source column is formatted as text and the values in the source column are truly entered as text (and not numbers, including dates), Excel may automatically convert text values to numbers (including dates) when you reference them in a formula if you use them in a place where Excel is expecting a number (or date).
For example (assuming US date formats), in a blank worksheet:
Set the format for column A to Text.
In cell A1, enter the value 10-11.
In cell B1, enter the formula =T(A1). The T() worksheet function returns the supplied value if it is text. Otherwise, it returns an empty string. The result of the formula in cell B1 should be 10-11, indicating that the value of A1 is text, not a number or date (in which case the result would be an empty string).
In cell C1, enter the formula =A1.
In cell D1, enter the formula =T(C1). The result should also be 10-11, indicating that the value of the formula in C1 is text, not a number or date. This shows that you can (sometimes) use a text value that looks like a number (or date) in a formula and have Excel treat it as text (which is what you want).
In cell E1, enter the formula =A1+0. The result will be 40827. This is the numeric value of the date October 11, 2011. This shows that you can (sometimes) use a text value that looks like a number (or date) in a formula and Excel will automatically convert it to a number (which is what you observed) if you use it in a place (like on either side of the + operator) where Excel is expecting a number.
To insert a value into a cell and have it not be auto-formatted, and just treated as text, you can enter it like this:
=("cell data")
eg:
=("+1 3456789")
When you use &"", Excel converts the results of a formula to text (like *1 would convert to numbers).
Thus, you can use this formula:
=TEXT(A1;"jj-mm")&""
If you put a single quote in front of the text in the cell, it should be represented as text on all references:
'10-11
Just add zero to the input!
I was having a similar problem where I had a list of numbers with a text prefix (like FOO-1, FOO-25, FOO-979) but I just wanted the number part (1, 25, 979) so I could run another formula off of that. I was using SUBSTITUTE to replace the text portion with blank, but my other formula using these numbers was coming up with bogus results. I ended up making my formula like this:
=SUBSTITUTE(B1:B10,"FOO-","")+0, and now the ISNUMBER is saying TRUE where before it was saying FALSE.
In my case, I have a form worksheet that is used by dealers to ad parts and have it calculate the final cost; it references a locked "products" sheet. The problem is that I had no way of controlling what they entered.
Products can be like:
101 = A true number
7-2009 = Reads as date
7-5601-RT = TEXT/NUMBER reads as both number or text (NOT SOLVED YET)
CP6072CD = reads as plain text
I have most of this figured out; the only one that isn't is the one that reads as both text/Number.
In case anyone is looking for a similar solution, i did the following:
I created three additional columns to test and display the three different cases: "NUMBER", "DATE" , "TEXT".
DATE: =NOT(ISERROR(DATEVALUE(B42)))
ISOTHER: =(ISNUMBER(--(MID(B42,ROW(INDIRECT("1:"&LEN(B42))),1))))
NUMBER: =ISNUMBER(B42)
NUMBER/TEXT: =NOT SOLVED YET
I42 = DATE
J42 = NUMBER
K42 = OTHER
L42 = TEXT
M42 = THE RESULT OF THE QUERY BELOW
=IF(AND(I42 = FALSE, J42 = FALSE, K42 = TRUE), "NUMBER", IF(AND( I42 = TRUE, J42= FALSE, K42=TRUE), "DATE", "TEXT"))
This (ABOVE) tests all the true/false results and depending on what the value turns out to be, I format each of them using:
ISNUMBER = VALUE(B42)
DATE FORMATTED AS B42*1
ELSE TEXT - AS ORIGINAL
=IF(M42 = "NUMBER", VALUE(B42), IF(M42 = "DATE", B42*1, B42))
So now I just need to figure out how to test if something is both text and number because the 7-5601-RT tests out as the same as number: "FALSE, FALSE, TRUE, TRUE"

Resources