Month Short Names and Regional Format in Excel - excel-formula

I have the Windows 10 Display, Apps & websites language as English and my Regional format as Portuguese. In Excel Options > Language the settings are Editing Language: Portuguese; and Display Language: English.
For some reason, I can't make Excel recognize the short name "mmm" of some months (those which differ from the corresponding Portuguese short names) has a date format. For instance: I have a column header which states 'Product Feb 2021 Sales Un' on which I can isolate the 'Feb 2021' part. Next, I would want Excel to recognize the month and calculate the number of days for each month, in order to use this value for a daily avarage metric (as in 'cell reference/number of days'), but everything I tried failed so far. Even when I test a simple formula like '=EOMONTH(TEXT(V39;"[$-0816]mmm aaaa");0)' it returns the #VALUE! error, because it doesn't recognize 'Feb 2021' as a valid date format, as opposed to 'Jan 2021' because in the former the 3 letters of the month are different, while in the late they are the same in EN and in PT.

Try [$-0016] instead of [$-0816]

Related

Excel interprets date entered differently among many users

I have a file with columns configured to format dates as yyyy/mm/dd. It's a shared file with a small team. Whenever I type "January 13" in a cell in the column, it returns a value of 2018/01/13, which is what the team wants. However, when my other colleagues enter the same "January 13" in that column, it returns a 2013/01/01 value. It's like Excel is interpreting the "13" as the year on his/her unit. We all use the same 2013 version and same computer model/type/brand.
What we tried so far:
-Comparing Excel applications to ensure the same configurations
-Saving the file as .xlsx instead of .xls
-Redoing the sheet into a new one
-Closing and opening the sheet
Yet none still worked. We hope to not go on the option of typing the whole date (January 13, 2018) as we somehow our fingers are dexterously trained to typing just January 13. Any insights on this please? Thanks! :)
The problem is in the Windows Regional Short Date settings.
If the short date settings are a variation of MDY, Excel will interpret your input(spelled out month and digits) as MD
If the short date settings are a variation of DMY; Excel will interpret your input as MY
In both cases, the Month is unambiguous. The short date format then interprets the digit based on the token following the Month token.
You will also see different results if you enter dates such as 1-12 vs 1-13 in the different environments.
If changing the short date settings is not an option (and the settings involved are MDY and DMY), one fix would be to always enter the dates as dd mmmm (13 January) as that would be interpreted as Jan 13, current year in either environment.
I would select all the cells/rows/columns that have dates and customize the format. Go to Home>Number and click on the dropdown (it might say "General" or "Short Date" or something). Click on "More Number Formats" and go to "Custom". In the cell under "Type:" put yyyy/mm/dd . Any way you type the date it should come out the same now. Either way, typing in number format should be easier than typing the month name.

What item in Windows 10 regional settings controls the interpretation of Excel TEXT() parameter 2

I live in Holland, but my copy of Windows is English, not Dutch, and my regional settings specify decimal points not commas, list separator commas not semicolons, etc. My copy of MS Office is also English not Dutch. I know this is true because I had to buy the Dutch spell checker separately: only English, French and German were included.
Following a recent Windows Update (March or April, I think), my copy of Excel started expecting Dutch-language format strings. So before, if I had a formula
=TEXT(TODAY(), "yyyy-mm-dd")
I would see 2018-05-20. After the change, this formula yields yyyy-05-20 and the only way to get it to work is to change the formula to
=TEXT(TODAY(), "jjjj-mm-dd")
The same change affected custom number formatting in Excel, in the dialogue box Format Cells | Number | Custom.
My question is, which particular setting in Regional Settings or which particular registry key controls this behaviour? I've already tried everything I can think of, so answers of the form change it in Regional Settings will not be helpful. The settings I have are
Region & language
Country or Region: United Kingdom
Windows display language: English (United Kingdom)
Preferred languages:
English (United Kingdom) - Windows display language
English (United States) - Language pack installed
Date & time
Time zone: (UTC+01:00) Amsterdam, Berlin, Bern, Rome Stockholm, Vienna
Formats
First day of week: Monday
Short date: 2018-05-20
Long date: Sunday 20 May 2018
Short time: 23:43
Long time: 23:43:46
Change date and time formats
Short date: dd/MM/yyyy
Long date: dddd, d MMMM yyyy
Short time: HH:mm
Long time: HH:mm:ss
Note particularly that Windows regional settings offer me yyyy and HH but Excel insists on jjjj and uu.
And my Office Language Preferences don't mention Dutch anywhere, except as Not installed:
I suspect this is a magic registry setting but intermittent googling over a period of 6 weeks or more hasn't yielded anything usable.
There are a bunch of different places where the locale is mentioned. I believe the one you need to change, for the daycode, monthcode and yearcode settings in Excel, is on the Region dialog box Formats tab. Change the Format entry to the country/language of choice.

Excel: Check whether a cell has text in another cell and with symbol, or trim left and right

So i have cell from long text from formula witch
=RIGHT(J2;15)
2016-07-22 2016
How to take out both 2016- and 2016 using find? It needs to be variable since in 2017 it wont be 2016. Can i find using something like FIND(K2&"-";J2)? Example below.
Result i need to get only 07
I used
=MID(LEFT(J2;FIND(N2;J2)-5);FIND(K2;J2)+5;LEN(J2))
But it finds both of 2016 and gives nothing
Wanted to something like
=MID(LEFT(J2;FIND(N2;J2)-5);FIND(K2&"-";J2)+5;LEN(J2))
But doesnt work
Pulling the left 10 characters off the text string should allow direct conversion to a true date using the DATEVALUE function (possibly assuming the conputer's correct system DMY vs. MDY regional setting). Once that true date has been achieved, a wrapping TEXT function can resolve any part of the date (e.g. year, month or day).
=TEXT(DATEVALUE(LEFT(J2, 10)), "mm") ◄ month as text representing a number
=--TEXT(DATEVALUE(LEFT(J2, 10)), "mm") ◄ month as true number

Converting String to Date in Excel

I've got date strings formatted this way: "Tuesday, January 3, 2012"
How can I convert them in a date format in Excel 2010?
Thank you in advance!
What works can depend on regional settings. If you have US regional settings this formula will give a date based on your data in A1
=TRIM(REPLACE(A1,1,FIND(",",A1),""))+0
format in required date format
This version should work on a wider range.....
=TRIM(MID(A1,LEN(A1)-7,2)&REPLACE(REPLACE(A1,LEN(A1)-7,3,""),1,FIND(",",A1),""))+0
Try this version which should work for Italian settings - [I assume the data is in English as shown, e.g. months are January, February etc.]
=DATE(RIGHT(A1;4);SEARCH(MID(A1;FIND(",";A1)+2;3);"xxjanfebmaraprmayjunjulaugsepoctnovdec")/3;MID(A1;LEN(A1)-7;2))
There's the DATEVALUE worksheet function which converts text to dates, however it doesn't seem to accept "Tuesday, January 3, 2012". But it does accept e.g. "3 January 2012" so if you manipulate the string into that format you should be able to get it to work.
Just a thought, these data functions like DATEVALUE often depend on your display settings for date, so what works for me in London UK may be different if you're elsewhere in the world with different display settings.

.NumberFormat sometimes returns the wrong value with dates and times

It seems that every week or so someone posts a question about dates being converted (corrupted?) to American format. Like many others, I have attempted to help but the problem is elusive. I now wonder if I have discovered the cause.
I am working on an application in which I need to extract data from an Excel worksheet and output it as strings formatted to match the value the Excel user can see. So if the value is “1” formatted to display as “1.00” then I want the string to be “1.00”.
I achieve this effect by testing the cell value to be a number, date or time. If it is, I retrieve the number format and use it to format the cell value so:
With .Cells(Row, Column)
Output string = Format(.Value, .NumberFormat)
End With
In most cases this gives me exactly the output I require. However, sometimes I get American dates and times when the source is formatted as a UK date or time.
After much experimentation with Excel 2003 and Excel 2007, I have discovered the cause. (I do not have access to Excel 2010 but from questions I deduce it has the same problem.) This question is in part intended to reveal this problem to the world because I can discover nothing on the internet to indicate that anyone else has noticed it. (No doubt someone will reply that they googled “xyz” and got the answer immediately.) However, the main purpose of this question is to seek suggestions for obtaining the result I need in all situations.
Typically I enter dates as, for example, “23mar12”. Excel recognises this as a date and formats it as “23-Mar-12”. I can select Format Cells and enter or select a custom format or select one of the date formats so I can have any format I can imagine wanting including non-English names for days and months.
However, in one case the format I select is not the format that is recorded: Custom format “dd/mm/yyyy” is recorded as Date format “* 14/03/2001”. This is not obviously a problem until further down the line.
I created a column of dates and times and formatted each with a different custom or standard format. I wrote a macro to extract the NumberFormat for each of these dates and times and write it as a string to an adjacent column. I also formatted the value using the number format and wrote that string to a third column.
In a number of cases the format selected and recorded by Excel was not the format returned by NumberFormat:
Excel format NumberFormat
Date: * 14/03/2001 m/d/yyyy
Date: * 14 March 2001 [$-F800]dddd, mmmm dd, yyyy
Date: 14/03/2001 dd/mm/yyyy;#
Date: 14/03/01 dd/mm/yy;#
Date: 14/3/01 d/m/yy;#
Date: 14.3.01 d.m.yy;#
Date: 2001-03-14 yyyy-mm-dd;#
Date: 14 March 2001 (1) [$-809]dd mmmm yyyy;#
Date: 14 March 2001 (2) [$-809]d mmmm yyyy;#
Custom: hh:mm:ss h:mm:ss
Time: * 13:30:55 [$-F400]h:mm:ss AM/PM
Time: 13:30:55 (1) hh:mm:ss;#
Time: 13:30:55 (2) h:mm:ss;#
Time: 01:30:55 PM [$-409]hh:mm:ss AM/PM;#
Time: 1:30:55 PM [$-409]h:mm:ss AM/PM;#
The values (1) and (2) in the Excel format column were added by me to indicate that there are two apparently identical formats. As can be seen from the NumberFormat column, in each case the second version suppresses a leading zero.
Most changes have no important effect. “[$-F800]” and so on are apparently dummy values with no effect. Apparently you can replace “F800” with an Microsoft country code to have the names of days and months translated to the language of that country.
However, the three standard formats that Microsoft marks with an asterisk are changed unacceptably. The dates are changed from little endian to middle endian; the time is changed from 24 hour to 12 hour and the day of the week has been added to “* 14 March 2001”.
The asterisk against the dates, references the comment: “Except for items that have an asterisk () in the Type list (Number tab, Format Cells dialog box), date formats that you apply do not switch date orders with the operating system.” The asterisk against the time, references the comment: “Except for items that have an asterisk () in the Type list (Number tab, Format Cells dialog box), time formats that you apply do not switch time orders with the operating system.”
If I have to, I can warn my users that standard date and time formats may not give the result desired. However, if they want the popular format “dd/mm/yyyy”, they cannot have it. “dd-mm-yyyy”, for example, is OK but custom format “dd/mm/yyyy” becomes date format “* 14/03/2001” becomes “m/d/yyyy”.
Returning to my opening point: is this strange handling of one particular date format the reason so many people claim their dates are sometimes being converted to American format and is this why the problem is so elusive? I have come across this type of problem elsewhere of one group of Microsoft programmers not knowing what another group are doing. Is this why some functions always work and other sometimes don’t? Some Microsoft programmers know where to look for the correct format and others don’t?
More importantly, for me, can anyone suggest:
How I obtain the true date or time format?
Some other way of determining the user’s chosen display format for a date or time?
BTW 1: I recall that thirty or so years ago I was told that the American military do not use month/day/year format; only American civilians use this format. Can anyone tell me if this is true?
BTW 2: The similar problem is with Excel colours. Excel holds its colours as "ggbbrr" while everybody else holds them as "rrggbb". The programmers for the .Net Excel inter-op were not told and and did not reverse the Excel colour number before using it to control the screen.
I have mainly come up against formatting and date issues when opening text files which have been saved with different regional settings. Two useful cell properties for dealing with this are:
.Text returns the cell value as it is displayed
.Value2 returns the unformatted cell value or date serial number.
As you say, standard date and number formats depend on windows regional settings and this may not be desired behavior as the same workbook can display differently in different regions. MS introduced the regional code prefixes in number formats (circa Excel 2000?) which enforce consistent display if needed but they need to be explicitly selected.
If you really want to see a date or number as the user entered it, you could extract the contents of the .xlsx file looking at the worksheet cell format and the shared strings xml definitions which list the number formats in the saved workbook. I don't really see a need to do this though as the underlying value is stored internally as a serial number and this will not change.
BTW 1: It's been almost 30 years since I was in the military...
I worked on helicopters and I was taught to use a format such as this in the aircraft logbooks: 3 Apr 12. So, that's how I still write dates. This way, there's no wondering about 4/3/2012 - is it April 3 or March 4?
I hacked this: I rewrite the original data in a known format. it relies on DateSerial and TimeSerial:
'Google spreadsheet stores dates in USA format (MM/DD/YYYY). We're in Australia, using DD/MM/YYYY, so we need to swap them.
'
With dc 'the cell who contains a date in USA format.
d = .Value 'capture value in USA format
t = TimeValue(d)
.NumberFormat = "dd/mm/yyyy" 'set to OZ format, so Excel knows the values were swapped in its internal math.
.Value = DateSerial(Year(d), Month(d), Day(d)) 'DateSerial takes y,d,m. We swap Month and Day components, to get OZ format dates
.Value = .Value + TimeSerial(Hour(t), Minute(t), Second(t))
dc.Font.Bold = True ' We bold the cells that are swapped, for debugging
End With
End If

Resources