I have a bunch of time data that's formated weirdly, ranging from numbers 100 (representing 1 AM, or 01.00.00) to 2359 (representing 11.59PM, or 23.59.00).
I have been trying to use the TIMEVALUE() function to convert these data, but it just returns #Value?, I guess because the time format 'HHMM' is not recognized without the ' : ' separating them?
What I'd like is to convert it to the HH:MM:SS format, where the SS would automatically be zero.
Use REPLACE:
=--REPLACE(A1,LEN(A1)-1,0,":")
Then format it as desired.
If your text values are consistent, this can be carried out by using a formula that splits the value by the number of characters and then recombines the split values into a time value.
All formulas assume that your weirdly formatted text value is in cell B2
=IF(LEN(B2)>3,LEFT(B2,2),LEFT(B2,1))
This formula works out the first (hour) element of a time, if the text string is greater than three characters it will take the first 2 characters of the string (23), if its less than 3 characters it will only take the first character (1)
=RIGHT(B2,2)
This formula takes the second (minute) element of the time.
=TIME(C2,D2,0)
Finally this formula converts the two text elements into a string
C2 = The cell with formula 1 in it
D2 = The cell with formula 2 in it
This could all be written as the following formula if needed
=TIME(IF(LEN(B2)>3,LEFT(B2,2),LEFT(B2,1)),RIGHT(B2,2),0)
Related
We need to count how many occurrences of each number are in a cell over a range of cells in the same column and output a tally of the totals for each number. See the attached picture and the desired output in the column next to it. We tried other formulas found online in both excel and open office with no results.
letter Count
Working Count
Try the following formula in D1:
=LEN(TEXTJOIN("",TRUE,A:A,"#"))-LEN(SUBSTITUTE(TEXTJOIN("",TRUE,A:A,"#"),C1,""))
and populate down.
(you will need 2016 or later for TEXTJOIN)
Option 1
Single array formula (ctrl+shift+enter !) which will work for strings with a maximum length of [5] alphanumeric characters (but you can easily modify the formula by adding a few numbers in the hard-coded array constant {1,2,3,4,5}):
{=SUM(N(MID($A$1:$A$500,{1,2,3,4,5},1)=TEXT(C3,"#")))}
You can add some further trickery to let Excel define the array constant, so the formula will work for any length of the string of digits :
{=SUM(N(MID($A$1:$A$500,
COLUMN(INDIRECT("A1:"&CHAR(65+MAX(LEN($A$1:$A$500)))&"1"))
,1)=TEXT(C3,"#")))}
The part in the middle (COLUMN()) creates the {1,2,3,4,5} array. You might have seen other versions of this formula, without the CHAR, which I use to create a reference to e.g. cell E1 (knowing that 65 is the code for "A").
.
Option 2
This array formula (ctrl+shift+enter !) works in all Excel versions, but is not very "elegant" as you have to repeat the key part of the formula as many times as the maximum digits you have in your cells (this example is for max 3 characters):
{=SUM(
N(MID($A$1:$A$500;1;1)=TEXT(C3;"#"))+
N(MID($A$1:$A$500;2;1)=TEXT(C3;"#"))+
N(MID($A$1:$A$500;3;1)=TEXT(C3;"#")) )}
The character you are counting is in C3. This will work for numbers and letters. If you can have five alphanumeric characters, you have to add two more N(...) parts, and replace the second parameter of the MID function with 4 and 5 respectively.
I am attempting to add three cells which I have formatted as hh:mm:ss
and it is giving me incorrect sum as one of them is missing hh
A B c
01:01:01 :01:01 01:01:01 SUM(A,B,C)
is returning 2:02:02 when it should be 2:03:03
I have several cells missing the HH so it is throwing off all my formulas, any way I can force the 00:01:01, on a cell that is :01:01?
Try,
=SUMPRODUCT(TIMEVALUE(RIGHT("00:00"&TEXT(A2:C2, "[hh]:mm:ss;#"), 8)))
The format mask used by the TEXT function (hh:mm:ss;#) converts real time values to text-that-looks-like-time and leaves values that are already text-that-looks-like-time unchanged. Leading zeroes and a colon are concatenated onto the result as a prefix and the right-most eight characters are parsed off with the RIGHT function. This should cover both :00:00 and :00 text values. This allows the TIMEVALUE function to process the resulting text to a true time value. The SUMPRODUCT wrapper produces cyclic calculation so that you don't have to sum three largely redundant formulas.
In the following sample image, note the default left alignment of B2 indicating text while A2 and C2 are right aligned indicating a true number, date or time.
If the values will always be contiguous as you show, you can try:
=SUMPRODUCT(--("00"&A1:C1))
Prepending "00" and the double unary will have no affect on the real time values, but will convert the "missing hour" value to a real time
i am trying to convert a number into decimals of a foot in excel. here is my formula
=IF(C2="", "",ROUND(LEFT(C2,FIND("-",C2)-2)+SUBSTITUTE(REPLACE(C2,1,FIND("-",C2),""),CHAR(34),"")/12,4))
If Cell C2 is 41-9, it returns 4.75
it works fine except when excel automatically changes cell c2 to a date such as 8-8. any ideas?
Format C2 as text before you enter the value. Then it won't convert to date.
But your formula will still not work, because it does not handle single digits for the foot measure well. The single digit will result in a blank text result from the Left() function, which causes an error when that blank text is added to the extracted number of the Substitute bit.
Wrap an N() function around the Left(), which will turn a blank result into a zero, and then the formula works (given the cell format is text, not date).
=IF(C2="", "",ROUND(N(LEFT(C2,FIND("-",C2)-2))+SUBSTITUTE(REPLACE(C2,1,FIND("-",C2),""),CHAR(34),"")/12,4))
I have a 12 digit number in column A like so:
Column A
041120121601
Within this number there is a date 201216 or 20/12/16.
I am trying to get the date from the number using mid:
=MID(B8,5,6)
I now get this as a result: 201216.
I am trying to format this as a date like this:
20/12/2016
Here's what i've tried:
=TEXT(D8, "00-00-00")
This gives me this:
20-12-16
This is close, but i need it to be 20/12/16
OK, if it starts with a 0, Excel doesn't think this is a number. It thinks it's text. This is important, because one day someone will copy and paste the input data and Excel will automagically convert them to numbers and your formulas all
will break because the leading 0 is missing now.
So, let's first convert the cell into a number, then back into text with "000000000000" format:
=Text(Value(A1),"000000000000")
Then apply the DateValue formula with three Mid functions as Tim describes.
(Or your input data are numbers in "000000000000" format, but that's a little unusual.)
You can your split MID and force a date separator betwixt each number and wrap it in DATEVALUE, then just format as a date.
=DATEVALUE(MID(B8,5,2)&"/"&MID(B8,7,2)&"/"&MID(B8,9,2))
If it's always the same amount of characters then =MID(TRIM(A1),4,2)& "/" & MID(TRIM(A1),6,2) & "/" & MID(TRIM(A1),8,2)
I need to extract the date from C2 and find the difference between the date in c2 and A1
The date is formatted as "Jul, 18 2015", any ideas? EDIT the database has a different amount of text per cell. Is there away around this so that i can apply the formula to every cell and pull the day/month/year?
you are going to need to go through a series of string manipulation and date time functions. Lets start by assuming your string is in the C2 cell. In order to do this we are going to work from the largest unit (years) to the smallest unit (days). You can do it in any order as it will all be lumped into once formula, but for the breakdown of steps its good to have an order.
Step 1) PULL OUT THE YEAR
=MID(C2,FIND(" ",C2,FIND(" ",C2)+1)+1,4)
That will give us the last 4 characters of the string after the second space which in this case is the year.
Step 2) PULL OUT THE MONTH
=MONTH(DATEVALUE(MID(C2,2,3)&"-"&1))
that looks at second character and pulls out the string 3 character long which is your month. It then converts it to a format that excel tends to recognize as a date short form by adding a - and the digit 1 to it. So in your case if would look like Jul-1. Datevalue converts this to an excel date serial, which we then pull back and grab the month from and in your case that is 7
If the above formula does not work for you it could be due to regional settings. If that is the case you can use the following:
=MATCH(MID(C2,2,3),{"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"},0)
If you use this alternat formula , be sure to adjust the final equation accordingly.
Step 3) PULL OUT THE DAY
=TRIM(MID(C2,FIND(" ",C2)+1,2))
So the above formula finds the first space and then starts pulling then next 2 characters after it. Now since I do not know if the first of the month is 01 or just 1, it may wind up grabbing the space after the 1. The trim function removes excess spaces.
Step 4) BUILD THE DATE
The DATE function in excel requires the YEAR, MONTH, and DAY and converts those values in to the excel date serial. In this case we will convert:
=DATE(year,month,day)
to the following by substituting our equations from above:
=DATE(MID(C2,FIND(" ",C2,FIND(" ",C2)+1)+1,4),MONTH(DATEVALUE(MID(C2,2,3)&"-"&1)),TRIM(MID(C2,FIND(" ",C2)+1,2)))
The final touch is to ensure your cell is formatted as date and not General or some other format which will result as the date being displayed in an integer format.
Now assuming you date in A1 is in Excel format, you would simply add A1- to the front of the last formula to give you:
=A1-DATE(MID(C2,FIND(" ",C2,FIND(" ",C2)+1)+1,4),MONTH(DATEVALUE(MID(C2,2,3)&"-"&1)),TRIM(MID(C2,FIND(" ",C2)+1,2)))
Now, if A1 is also in quotes like the C2 formula, repeat the formula for stripping the date out of C2 but use A1 as the reference and substitute it in for A1 in the last formula to give:
=DATE(MID(A1,FIND(" ",A1,FIND(" ",A1)+1)+1,4),MONTH(DATEVALUE(MID(A1,2,3)&"-"&1)),TRIM(MID(A1,FIND(" ",A1)+1,2)))-DATE(MID(C2,FIND(" ",C2,FIND(" ",C2)+1)+1,4),MONTH(DATEVALUE(MID(C2,2,3)&"-"&1)),TRIM(MID(C2,FIND(" ",C2)+1,2)))
FORMULAS USED
Text/String Functions
MID
FIND
TRIM
Date/Time Functions
DATE
DATEVALUE
MONTH