Currently I exported some data, from a database using a query in which each row for a "comment" column begins with a date formatted as MM/DD/YY.
I used the =LEFT(TEXT,8) function to only extract the date but it happens that the some of the dates are formatted inconsistently so we may have some that are M/D/YY where the month or day isn't two digits, this will then include a ';' as a separator since it is less than 8 characters.
Is there a way I can format the text so the ';' is excluded? That way I can sort the data.
I think the DATEVALUE function does most of what you need. It takes in many different date formats (M/D/YYYY, MM/DD/YYYY etc) and converts it to an excel date (i.e. # of days since 1/1/1900).
The formula below says:
If the date is clean then just apply DATEVALUE function
If there is an error, just use the part to the left of the ';'
Assuming 9/1/2013 is Cell A2:
Input Data Sortable Excel Date
---------- -------------------
9/1/2013; =IFERROR(DATEVALUE(A2),DATEVALUE(LEFT(A2,FIND(";",A2)-1)))
09/2/2013; 9/2/2013
10/1/2013; 10/1/2013
10/10/2013 10/10/2013
I've made a live Excel sample here.
Assuming your text looks like this: ;1/;2/13 or 1/2/13;; or ;;1/2/13
You can use substitute like this:
=SUBSTITUTE(A1,";","")
The result will be:
So if date is either the first 6, 7 or 8 characters of A2 you can get the date with this formula
=LOOKUP(10^10,LEFT(A2,{6,7,8})+0)
format result cell in required date format
As the result is a valid date you can sort these as you would sort numbers
Related
i have a column in excel where data is in mix format as some date are in dd/mm/yyyy and some date are in yyyy/dd/mm
i want to convert dates which are only in yyyy/dd/mm --> dd/mm/yyyyhttps://i.stack.imgur.com/5SOV1.png
what is the way i can do this?
i tried concatenate(left()) and concatenate(middle()) and concatenate(right()) and then concate() to combine all this 3 different fields but then it is messing up the true date format i want that is dd/mm/yyyy as some dates are already in dd/mm/yyyy and i made used concatenate() for format yyyy/dd/mm
Let's say you have the input data in text format in column A. In column B you have the output in the equivalent date format (not text format). This is the proper way to handle dates. You asked to convert it to another text format, but I think it is better to have them as an Excel date type.
The following formula does that:
=LET(rng, A1:A4, texts, DROP(REDUCE("", rng, LAMBDA(acc,text,
VSTACK(acc, TEXTSPLIT(text,"/")))),1),
first, INDEX(texts,,1), second, INDEX(texts,,2), third, INDEX(texts,,3),
MAP(first, second, third, LAMBDA(a,b,c, IF(LEN(a)=4, DATE(a, c, b),
DATE(c, b, a))))
)
The formula returns an array, so there is no need to drag down the formula, useful for a large input data set. If you prefer to drag the formula down, then you can use the following formula:
=LET(text, TEXTSPLIT(A1,"/"), first, INDEX(text,1,1), second, INDEX(text,1,2),
third, INDEX(text,1,3), IF(LEN(first) = 4, DATE(first, third, second),
DATE(third, second, first))
)
Note: If you really want the dates in text format, then you can do it by replacing DATE function with: a&"/"&c&"/"&b and c&"/"&b&"/"&a respectively or to encapsulate DATE output with TEXT function, for example, TEXT(DATE(a, c, b), "mm/dd/yyyy") in the format of your preference.
Here is the output:
The previous solution works because we have a way to identify the year as a 4-digit number. If the year has 2-digits, then you need to build a logic to differentiate a year from a month or a day.
Because the data is in Excel date format (internally it is stored as a whole number), then you can format the date in the format of your preference without changing the data. In the screenshot, you see the dates in mm/dd/yyyy format. Having the data as a date type, you can use all Excel functionalities for working with dates. Having dates in text data type will have more limitations.
Here is the output using the UK locale and returning the dates in dd/mm/yyyy, but it is the same output data, just different visualization:
Is there a method to convert these column in data format? (gg/mm/aaaa hh:mm:ss)
DATE : 20220601 >>>> 2022/06/01
HOUR : 3047 >>>>> 00:30:47 (hh:mm:ss)
I have serious problem with column B, i need to convert it in (hh:mm:ss). Someone can help me?
The final result should be "01/06/2022 00:30:47"
If you have Excel 365 you can use this formula:
=LET(HourText,TEXT(B2,"000000"),
DateText, A2,
HourFinal,TIME(LEFT(HourText,2),MID(HourText,3,2),RIGHT(HourText,2)),
DateFinal, DATE(LEFT(DateText,4),MID(DateText,5,2),RIGHT(DateText,2)),
DateFinal + HourFinal)
It first takes the text-hour and the text date.
Text hour is formatted as hhmmss - to have the zeros for hour if missing. Then it is easier to return the true hour.
Adding both values (date + hour (yes this is mathematical addition) returns the date.
You can then format the date as you like, e.g. as dd/mm/yyyy hh:mm.ss
Try-
=TEXTJOIN("/",TRUE,MID(A1,{1,5,7},{4,2,2})) & " " & TEXTJOIN(":",TRUE,MID(RIGHT("00"&B1,6),{1,3,5},{2,2,2}))
For pure date value use below function then use cell format to show your desired date/time format.
=DATEVALUE(TEXTJOIN("/",TRUE,MID(A1,{1,5,7},{4,2,2})))+TIMEVALUE(TEXTJOIN(":",TRUE,MID(RIGHT("00"&B1,6),{1,3,5},{2,2,2})))
Here is an easy alternative solution, using the TEXT() Function with a Custom Formatting for Dates 0000\/00\/00 while for Times 00\:00\:00
• Formula used in cell C2
=TEXT(A2,"0000\/00\/00")+TEXT(B2,"00\:00\:00")
So, the first part of the TEXT() function returns & converts the Numbers into Dates, while the second part returns & converts the Numbers into Times, and as we know that Dates & Times are stored as Numbers in Excel, so the Integer part which represents the Dates and the Decimal which represents Times, when added to together returns a Number with Decimals using the TEXT() Function.
Hence if the cells are not formatted before then please select the cell or range and press CTRL+1 --> Format cells Dialogue Opens --> Number Tab --> Category --> Custom --> and type by removing General as dd/mm/yyyy hh:mm:ss or as per your region it will be gg/mm/aaaa hh:mm:ss
Note: For more inspiration on converting Dates when shown like those numbers, you can refer this link, I have shared a whole lot of alternatives.
CHANGE THE DATE FORMAT
I'm trying to extract dates from the substring in column D2/D3 in column L2/L3. However, the date format within a substring differs. Sometimes the dates are entered in MM/YY format, or MM/YYYY format. Right now I'm using the formula below, but I have to change the 5 to 7, when the date in the substring is entered in MM/YYYY format.
=SUBSTITUTE(SUBSTITUTE(MID(D2,FIND("/",D2)-2,5),"-",""),"/","/01/")*1
example of substring in column D
If there will always be exactly 1 slash, then you can use a two step formula. Assume it is MM/YYYY. Try to extract that first as a date. If that fails, then it's the MM/YY format.
=IFERROR(
DATE(MID(D2,FIND("/",D2,1)+1,4),SUBSTITUTE(MID(D2,FIND("/",D2,1)-2,2), "-", ""),1),
DATE(MID(D2,FIND("/",D2,1)+1,2)+2000,SUBSTITUTE(MID(D2,FIND("/",D2,1)-2,2), "-", ""),1)
) \-----------------------------/ \---------------------------------------------/ ^
| | |
year month day
I had to use a function DATE() to build a real date value, so that if it fails it will return an error, so that it will use the second part to use a two digit year. (Don't include the year/month/day note in the actual formula...)
Or even better, since your formula already works for MM/YY, then if the first DATE() conversion fails, it will use your formula. That way you don't have to assume a YY value is the year 2000 or later...
=IFERROR(
DATE(MID(D2,FIND("/",D2,1)+1,4),SUBSTITUTE(MID(D2,FIND("/",D2,1)-2,2), "-", ""),1),
SUBSTITUTE(SUBSTITUTE(MID(D2,FIND("/",D2)-2,5),"-",""),"/","/01/")*1
)
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)
Following up on this earlier question: Excel - Convert date from yymmdd to dd/mm/yy
I would like to input only 4 digits and the formula convert to a date.
For example, if I enter value 1207, the formula will convert into 12/07/2014 but if I input 0311 it converts into 31/1/2014.
I couldn't work out how to do the date conversion when I input a date starting with "0" such as 0711.
The formula I'm using:
=LEFT(A2,2)&"/"&MID(A2,3,4)&"/2014"&RIGHT(A2,0)
See the wrong output highlighted below:
Input Date converted
1112 11/12/2014
1503 15/03/2014
2407 24/07/2014
2912 29/12/2014
0712 71/2/2014 <~~~~~~ should be 07/12/2014
0311 31/1/2014 <~~~~~~ should be 03/11/2014
You can use the formula as suggested by Jerry. I have same formula:
=DATE(2014,RIGHT(A2,2),LEFT(A2,2))
But, You need to make sure that your inputs are text. 0712 should be displayed as 0712 in excel. i.e keep you input to four digits then only this above formula will work. You can use apostrophe before 0712 to convert it as text, enter '0712 as input.
I'm not sure how you edited the other formula, but it should be working. In any case, there's one that works for your particular case:
=DATE(2014, RIGHT(A2,2), LEFT(A2,2))
Where A2 contains the date.
If your dates are actually numbers, then you might want to use a condition to change the result if the number is of different length:
=IF(LEN(A2)=4, DATE(2014,RIGHT(A2,2),LEFT(A2,2)), DATE(2014,RIGHT(A2,2),LEFT(A2,1)))