Ok so i have been trying to do this and i pretty much keep on failing :p
Basically what i want to do is take the date 10/1/2013 and turn it into 201310. I tried to concatenate using left and right. tried to make it into text using left and right. Nothing seems to be working. The closest i got was to 20130 by using =CONCATENATE(TEXT(J3,"mmyyyy")) Which turned the date into 102013 than i tried =RIGHT(L3,4)*LEFT(L3,2) and got 20130 which is still incorrect. Any help would be appreciated!
You could simply turn around your first example and use the correct string:
=TEXT(J3, "yyyyMM")
Note, I used upper case M. Lower case m means minutes, while upper case M means month.
The CONCATENATE is unnecessary.
Please also note, that this is prone to localization issues, i.e. it depends on the language settings. I am from Germany and I need to use jjjj instead of yyyy.
Related
I have a spreadsheet I need to make in Google Sheets. The source of some of the data is exported to an Excel sheet. The data arrives in a dd/mm/yyyy format and I need to display it in a MON d format (Ex Sep 5).
The problem is both excel and sheets look at the date that arrives and think it is mm/dd/yyyy.
For example, 02/08/2022 is believed to be Febuary 8 even though it should be Aug 2. The problem then arises that neither of these platforms end up knowing how to convert this to Aug 2 and I end up having to do this manually.
Does anyone know how to get around this?
I have tried adjusting the format of the date, as well as using DateValue to convert (this fails since it understands the date as mm/dd/yyyy even when it is dd/mm/yyyy).
Any leads would be appreciated!
Thanks!
In Google Sheets, choose File > Settings > Locale and select a locale that uses the dd/mm/yyyy date format, before importing the data. You can then format the date column the way you prefer.
in gs:
=TEXT(REGEXREPLACE(A1&""; "(\d+)\/(\d+)\/(\d+)"; "$1/$1/$3"); "mmm d")
Try the following and format the result to your liking
=INDEX(IF(ISNUMBER(U2:U5),U2:U5,
IF(U2:U5=DATEVALUE("1899-12-30"),,
(MID(U2:U5,4,3)&LEFT(U2:U5,3)&RIGHT(U2:U5,4))*1)))
(Do adjust the formula according to your ranges and locale)
Functions used:
INDEX
IF
DATEVALUE
ISNUMBER
TRUNC
MID
LEFT
RIGHT
Well, for a formulaic solution, if the date is in A1, then the following places the correct date in B1:
=DATEVALUE(TEXT(A1,"DD/MM/YYYY"))
The TEXT function makes a string that will be the same form as your imported string out of the date produced during import. DATEVALUE then gives the proper date you desired.
The trick is in the TEXT step in which you reverse month and day in the string for DATEVALUE.
Naturally, instead of a helper column, it could just be wrapped around any reference to a date from column A, though one would have to remember to do so for all the years the spreadsheet is in use.
If you are importing, not just opening a .CSV file via File|Open and going from there, you have an opportunity to solve all your problems. You use the Ribbon menuing system's Data menu, select the very leftmost thing, Get Data and from the (no arguing THIS isn't a menu) menu that drops down, Legacy Wizards, then finally From Text (Legacy) which will open the old Excel Import Wizard. (You may notice this is very like the Data|Text to Columns Ribbon menu choice and that is because that choice is the old wizard minus the steps at the start that go looking to another file for the data because it knows, by law, that it has to already be in the spreadsheet... in other words, it looks the same because it IS the same.)
Then make selections for the first couple dialogs it presents you to get to the dialog in which you tell it to import columns as whatever: general (let Excel decide), text, date, and do not import. Choose Date and make the selection of DMY to import them properly as you desire them to be so you are never presented with the problem at all.
As you might guess, you can use the abbreviated wizard via the "Text to Columns" feature to do the same thing after import when you see they are reversed. Since it is a single column of data, the result will overwrite the original simplifying your work.
Why does this happen at all? Well, the "locale" folks have the idea. When Excel imports numbers that are in a form it recognizes could be a date, it looks to the operating system settings for the selected ways dates are understood. So if your operating system believes a date should be displayed "Month Day, Year" and Excel has a set of data it thinks fits that mold, it will convert them all using it. So you get those Feb 8's rather than Aug 2's.
Interestingly, it does two other things of note:
It looks at 8, count 'em, 8 rows of data to decide the data fits the pattern. Even with 1,000,000 rows to import, it looks at... 8.
Then it does them ALL as if God himself wrote the "8"... and dates like 25/03/2022 get imported as text not a real date, because they (oh, obviously) can't be dates... "25" can't be a month!
It IS possible to change settings (DEEP settings) to make Excel consider X number of rows in a data set before deciding such things. I found them here, on the internet, once upon a time, though I shouldn't like trying to find them again. It will consider up to a million rows in such an import, but... that'd make it pret-ty slow. And that's a million rows for EACH data column. I won't even say that "adds up" - I'll point out it "multiplies up."
Another technique is to add some number of starting rows to force the desired pattern onto the import. I've heard it works in TIME column imports so it ought to in DATE column imports but I've not verified such.
My bet is you will find the use of the "Text to Columns" feature of most use if you can use a hands-on approach - it does require literal action on your part, but is a fast operation. If you will see others using the spreadsheet though... well, you need a formulaic solution or a VBA one (macro with button for them to have some fun clicking as their reward for doing what they were trained to do instead of complaining to the boss you make bad spreadsheets). For a formulaic solution, the above formula is simple.
Last thought though: there's no error-checking and error-overcoming in it. So a date like "25/03/2022" in the data that imported as literal text is a problem. For handling the latter, an up-to-date approach could be:
=IF(TYPE(A1)=1,DATEVALUE(TEXT(A1,"dd/mm/yyyy")),DATE(INDEX(TEXTSPLIT(A1,"/"),1,3),INDEX(TEXTSPLIT(A1,"/"),1,2),INDEX(TEXTSPLIT(A1,"/"),1,1)))
in which the DATE(etc. portion handles finding text of the "25/03/2022" kind. Lots of less up-to-date ways to split the text Excel would have placed in the column, but since demonstrating what to do if it existed was the point, I took the easy way out. (Tried for a simple version but it wouldn't take INDEX(TEXTSPLIT(A1,"/"),1,{3,2,1}) from me for the input parameters to DATE.) TYPE will give a 1 if Excel imported a datum as a date (number), and a 2 if brought in as text. If empty or strange strings could exist, you'll need to deal with what those present you as well.
I have a pretty large data set I with adresses and postal codes, and I need to organize said data set by postal codes only, which resulted in a large number of variables.
The code goes like this (it continues for a long while, but in order to shorten it for easier access and reading:
=IF(ISNUMBER(SEARCH("NEPAL";F2));RIGHT(F2;5);IF(ISNUMBER(SEARCH("MALTA";F2));RIGHT(F2;5);IF(ISNUMBER(SEARCH("SWITZERLAND";F2));RIGHT(F2;5);IF(ISNUMBER(SEARCH("CHINA";F2));RIGHT(F2;5);IF(ISNUMBER(SEARCH("CHILE";F2));RIGHT(F2;5);"OTHER"))))))
I had to translate the formula since I'm using EXCEL in Portuguese.
TL'DR: My formula hit the character limit (it's a lot bigger than what's above) and I still have some variables I need to add to the formula (eg.):
IF(ISNUMBER(SEARCH("ANGOLA";F2));RIGHT(F2;6)
and other variables with the same functions.
If anyone could help me shorten the string, I would appreciate it!
Used the solution sugested by #Rory and it worked perfectly for what I wanted! Thank you all!
How to compute day name from date in Excel?
Please don't say it is TEXT(...,"ddd") because it doesn't work
Another screenshots for non-believers:
Complete formula just doesn't work too:
This is some problem with locale processing. Although my Windows in English, my region is Russia and Excel uses it in some strange places:
TEXT(...,"ddd") ( or TEXT(...;"ddd") . as required )
does work, provided you either SUBSTITUTE the dots . in your data for recognisable date separators first (eg /) or apply Find/Replace for that purpose. Though having done either (perhaps working on a copy) no formula is necessary since merely a Custom format of:
dddd
(long form, or ddd short) should be sufficient.
Note that without indication of the century Excel will guess which and not give you the right answer for a date such as 11.11.1911 (Armistice Day, a Saturday) represented in text as 11.11.11.
With string parsing you would need to be careful whether 10.08 represents October 8 on your system, or August 10.
We can always manually build one : =if(WEEKDAY(A1,2)=7,"Sunday",if(WEEKDAY(A1,2)=6,"Saturday",if(WEEKDAY(A1,2)=5,"Friday",if(WEEKDAY(A1,2)=4,"Thursday",if(WEEKDAY(A1,2)=3,"Wednesday",if(WEEKDAY(A1,2)=2,"Tuesday",if(WEEKDAY(A1,2)=1,"Monday","")))))))
[^_^]
I have a working formula for the following text to date conversion. However, I don't understand why the trailing 0 has to be added in order to show the year in YYYY format.
21.04.2016 converts to 4/21/2016
=(MID(A2,4,2)&"/"&LEFT(A2,2)&"/"&RIGHT(A2,2))+0
It's very simple and straight-forward. However if you remove the 0 at the end of the formula, it will only show 16 instead of 2016. But I could do Right(A2,4) instead of Right(A2,2). But I still like to know why? Anyone? Thanks!
The trailing zero turns the whole thing into a math operation which causes the string (everything to the left of the +0) to be treated as a number.
you could also use *1 instead of +0
=(MID(A2,4,2)&"/"&LEFT(A2,2)&"/"&RIGHT(A2,2))*1
or you could drop the +0 and at the front add -- before the ( and it should all do the same.
=--(MID(A2,4,2)&"/"&LEFT(A2,2)&"/"&RIGHT(A2,2))
As Ed has correctly answered, this is because it is treating your date string as a number.
However, Excel has to interpret the string to get what number it really is, and to do this it relies on regional settings.
Under US regional settings, your formula works great, but when I plug it into excel with UK regional settings I get #Value because "04/21/16" isn't a valid date or number in the UK.
In order to avoid this problem, you should convert it to a date using the DATE() function, which will work irrespective of your regional settings.
=DATE(RIGHT(A2,4),MID(A2,4,2),LEFT(A2,2))
I have following problem:
I want to extract time interval from string like
time=10PM-12AM!991408111200000
The problem is, I need it in 24hrs format, so 10PM-12AM should be 22 and 00 in two different cells. I tried several solutions, but nothing worked for all possible intervals. Do you have any idea how can I do that? Thanks a lot!
This should work. Assume that your original string is on A1. The first code is for the first portion of the time. The second is for the time after the dash.
=TEXT(IFERROR(REPLACE(MID(A1,FIND("=",A1)+1,FIND("-",A1)-1-FIND("=",A1)),FIND("PM",MID(A1,FIND("=",A1)+1,FIND("-",A1)-1-FIND("=",A1))),2," PM"),REPLACE(MID(A1,FIND("=",A1)+1,FIND("-",A1)-1-FIND("=",A1)),FIND("AM",MID(A1,FIND("=",A1)+1,FIND("-",A1)-1-FIND("=",A1))),2," AM")),"HH:MM")
=TEXT(IFERROR(REPLACE(MID(A1,FIND("-",A1)+1,FIND("M",A1,FIND("-",A1))-FIND("-",A1)),FIND("PM",MID(A1,FIND("-",A1)+1,FIND("M",A1,FIND("-",A1))-FIND("-",A1))),2," PM"),REPLACE(MID(A1,FIND("-",A1)+1,FIND("M",A1,FIND("-",A1))-FIND("-",A1)),FIND("AM",MID(A1,FIND("-",A1)+1,FIND("M",A1,FIND("-",A1))-FIND("-",A1))),2," AM")),"HH:MM")
The reason this is so long is because I am not sure if your data always comes up with four characters for the time. For example, if your data has time=3PM-6PM this should be smart enough to understand that there is less spaces in between. This also assumes that the exclamation mark just happened to be randomly there rather than always there.
Let me know if you have a problem.