Excel TEXT formula doesn't convert 'yyyy' to a year - excel

I want to combine some text with a date in Excel 2013.
Let's say I have a cell A2 with a date like 30-10-2014. I tried to append the date after the text with this formula:
="Some text and a date: "&A2
But the output shows the date as a number: Some text and a date: 41942
So I tried it with the TEXT formula:
="Some text and a date: "&TEXT(A2;"dd-mm-yyyy")
But this shows Some text and a date: 30-10-yyyy and not Some text and a date: 30-10-2014
So or I do not understand how the TEXT formula works or is there some bug / issue here?
UPDATE: It looks like it's important that I have a Dutch version of Windows (7) but an English version of Excel (2013) which causes this issue!

All kudos go to #AxelRichter, thanks Axel!
It looks like that if you have a Dutch Windows but an English version of Excel (2013) the formulas get mixed up. For example, I still have the English formula names like TEXT (which would be TEKST in Dutch) but still have to use a colon instead of a comma in the formula. The format_text value of TEXT still expects the Dutch format which is different for the year (jjjj instead of yyyy).
So if you have a Dutch Windows and an English Excel version the correct formula for some text followed by a formatted date would be:
="Some text and a date: "&TEXT(A2;"dd-mm-jjjj")
I hope Microsoft will fix this, this is very annoying!

You can now use 'e' instead of 'yyyy'. The e is the universal version of yyyy a

we have the same issue at our work and I found that if I cannot influence the localization of the windows then I use a formula which in your case looks like:
="Some text and a date: "&TEXT(A2;"dd-mm-")&YEAR(A2)
It is funny that "dd" and "mm" is the same.

Excel here obviously fails. TEXT should be language agnostic.
The workaround I found, especially if you have multiple cells to format:
Calculate the desired date format in a hidden cell or white colored:
=IF(TYPE(VALUE(TEXT(DATE_CELL;"YY")))=1;"DD.MM.YYYY";"ДД.ММ.ГГГГ")
If you need, it can be extended to support multiple regions like:
=IF(TYPE(VALUE(TEXT(DATE_CELL;"YY")))=1;"DD.MM.YYYY";IF(TYPE(VALUE(TEXT(DATE_CELL;"ГГ")))=1;"ДД.ММ.ГГГГ";"DD.MM.JJJJ"))
On cells where you need dates, use previous cell as second parameter:
="Date: " & TEXT(DATE_CELL; FORMAT_CELL)

For same problem when your system or keyboard is Danish then use åååå in place of jjjj. I also struggled a lot to find this key.
However if anyone facing same problem apart from Dutch or Danish then you can check which key is correct. To find it right click on any cell and goto 'Format Cell' then select 'Custom' and find date related formats in your local language. There you can find which is the right key to be used for DATE format in your local language.

This issue is still there on Excel 2016 (or Office 365, if you may). It is caused by different language settings in Windows. This happens for languages that have different year symbols (dutch is 'jjjj', portuguese is 'aaaa'). If you're experiencing this problem, try using your local Windows language's year format.

This should work regardless of your system language or regional settings:
="Some text and a date: "&TEXT(DAY(A2);"00")&"-"&TEXT(MONTH(A2);"00")&"-"&TEXT(YEAR(A2);"0000")
Click here to see it working
[Edit] I just tested the solution with German (TT.MM.JJJJ) and English settings (DD.MM.YYYY) and it works fine!
You may need to use , instead of ; in the MS EXCEL formula (depending on your actual list separator symbol --> check your OS settings!).

Solution: To check if "jjjj" format is working:
The date you want to display in a certain format is in A1
In cell A2 link a cel to the cel with the date you want displayed in a certain format with the following formula:
=TEXT(A1;"dd/mm/jjjj")
In a 3rd cel you then place the following formula:
=IF(RIGHT(A2;4)="jjjj";TEXT(A1;"yyyy");TEXT(A1;"jjjj"))
If the 4 digits from the right are "jjjj" this formula will display the date formatted as "yyyy" else the formatting "jjjj" will be used.

The easy fix, whether directly custom formatting a cell or using TEXT(), is to use a country code for a language you know the proper formatting codes for.
For instance, I am in the US, have a US version of Excel, and am familiar with its date code formats. So I'd want to use them and to ensure they "come out" regardless of anyone's Windows or Excel version, or the country they are in, I'd do it like the following (for TEXT(), let's say, but it'd be the same idea in custom formatting):
=TEXT(A1,[$-en-US]"dd-mm-yyyy")
The function would collect the value in A1, ask Excel to treat it as a date, Excel would and would say fine, it's cool (i.e.: the value is, say, 43857 and not "horse") because it is a positive number which is a requirement for anything to be treated as a date, and let the function move on to rendering it as a date in the manner prescribed. Rather than giving an #ERROR! as it would for "horse" or -6.
The function would then read the formatting string and see the language code. It would then drop the usual set of formatting codes it loaded upon starting up and load in the formatting codes for English ("en") and in particular, US English ("US"). The rest of the string uses codes from that set so it would interpret them properly and send an appropriate string back to TEXT() for it to display in the cell (and pass on to other formulas if such exist).
I have no way to test the following, but I assume that if one were to use a format that displayed day of the week names or month names, they would be from the same language set. In other words, Excel would not think that even though you specified a country and language that you still wanted, say, Dutch or Congolese month names. So that kind of thing would still need addressed, but would be an easy fix too just involving, say, a simple lookup one could add though it'd be "fun" setting up the lookup table for each language one wanted to accomodate...
However, the basic issue that arises here, and with this problem in general, is very, very easily solved with the country codes. They aren't even hard or arcane anymore now that the [$-409] syntax has been replaced with things like [$-en-us] and [$-he-IL] and so on.

If VBA is an option... works for any locale/language
Public Function dateYYYYMMDD(dt As Date) As String
dateYYYYMMDD = Format(dt, "yyyyMMDD")
End Function

Related

How do I make Excel read my not completely filled in dates correctly in my regional format? (dd.mm)

I have used a previous version of Excel and OpenOffice Calc, and I was able to format dates to the Ukrainian format "dd.mm.yy" so that when I typed for example "1.8" in the cell marked with this format, it correctly read it as "01.08.22" (the first of August of the current year). Now I'm using the newest Excel and for some reason when I type in "26.08", it autocompletes as "26.01.00" with the following in the formula section: "1/26/1900 12:14:24 AM". Now I could understand not filling in the year I want it to, but not even the month?
And when I do fill it in fully, I don't think it recognizes the text as a date at all! The dates filled in previously in the same document are interpreted and formatted correctly, but not the new ones. The format is identical, I formatted the whole range of cells together.
Typing "8/26" gives me the desired date, but it's not my regional format and it's inconvenient to use.
Is there a way to make Excel do what I want, here?

Excel danish region change TT:MM [duplicate]

A B
1 2020-01-01 2020-01-01 =TEXT(A1,"YYYY-MM-DD")
2
3
In my spreadsheet I have a date written in Cell A1 and change it to a TEXT format with the formula in Cell B1.
All this works fine as long as I use the English version of Excel.
Now, a coworker in Poland needs to use the file in a polish Excel version.
Once he opens the file the formula in Cell B1 changes to:
=TEKST(A2;"YYYY-MM-DD")
This formula gives back an error because in Poland instead of YYYY-MM-DD you need to use RRRR-MM-DD.
Therefore, I am wondering if it is somehow possible to make this text formatting international so no matter in which language your Excel is set up the formula is working?
If the only problem is sharing it with your Polish co-worker, then you can simply use the international placeholder "e" to replace "YYYY":
=TEXT(A1,"e-MM-DD")
Now, while this would work fine for your co-worker in Poland, there are countries where "m" and "d" would also need replacement. If in general we need to return the locale "Y", "M" or "D" equivalent you could create three named formulas using the name manager:
1st: Create name called YT and refer to =INDEX(GET.WORKSPACE(37),19)
2nd: Create name called MT and refer to =INDEX(GET.WORKSPACE(37),20)
3rd: Create name called DT and refer to =INDEX(GET.WORKSPACE(37),21)
Now you can use a reference to these names through:
=TEXT(A1,REPT(YT,4)&"-"&REPT(MT,2)&"-"&REPT(DT,2))
NOTE: Depending on which version of Excel you use it could be necessary to:
Enable Excel 4.0 macros when VBA macros are enabled in the Trust Center
Another option with no macros is to use FORMULATEXT:
In a random cell Z5
=TEXT(123, "foo")
Then in your desired cell C1
=TEXT(A1,IF(ISERROR(SEARCH("TEKST", FORMULATEXT(Z5)), "YYYY", "RRRR") & "-MM-DD")
This works because the formula of the random cell will be updated to say TEKST in polish and you can just spot that happening. Obviously the other method is more robust to any country but this requires no settings to be changed.
Bigger:
=TEXT(
A1,
IF(
ISERROR(
SEARCH(
"TEKST",
FORMULATEXT(Z5)
),
"YYYY",
"RRRR"
) & "-MM-DD"
)
The solution is actually simple, surprisingly so.
Whether specifying a formal Custom Format, or specifying a format inside a TEXT() (or TEKST() function), you just add the country-specific code for interpreting the formatting string. So, if a US-Excel version person is writing the formula, and is presumably most conversant in the US English strings to use, and especially if expecting the users to be US-Excel version users, he would write it as:
=TEXT(A1,"[$-en-US]YYYY-MM-DD")
Every version of Excel will then use the US English set of formatting string variables in interpreting the formatting string that follows the [$-en-US]. Since the string is perfectly valid in US English Excel, it will form the date properly and "textify" it as demanded. No error will be produced.
I cannot test a nuance here, that of whether Excel of a different language version will insert itself into the middle here and take the date as the string formats it, and map it to the particular language's names for months, but that is not asked for in the poster's question so... I have the feeling it will not and so one might need to do further work to make the Polish user happiest. If month names were used instead of month numbers.
But the key element of generating a correct numeric date display with no possibility — none at all — of an #ERROR! result rendering things ugly and useless will absolutely be accomplished with no great effort at all.

Excel EOMONTH date function

I am trying to use EOMONTH in excel, but I cannot make it work... It i not recognising my date as a date.
I am using excel for mac (ver16.45), in column I type for example 01.01.2020, or 01/01/2020 it always formats as 1.1.20. When I try to change formatting I have asterisk for default date as in my system as *14.3.12 and I leave it like that... than when I use =EOMONTH(C1,0)...
I am getting error ("Not trying to type a formula?
When the first character is an equal ("=") or minus ("-") sign, Excel thinks it's a formula")
I know that for EOMONTH excel need to recognise data as a date, and that it needs to be in format of the system... but for me is simply not working...
I don't know is it mac maybe, or what can be...
Thanks!
It would be helpful if you could upload a copy of your workbook, or at least a screenshot of your scenario, so I can get a full understanding of your request. Based on your initial comment, can you replicate my screenshot and let me know if it works?

Date-Formatting in TEXT formula independent from used language in Excel

A B
1 2020-01-01 2020-01-01 =TEXT(A1,"YYYY-MM-DD")
2
3
In my spreadsheet I have a date written in Cell A1 and change it to a TEXT format with the formula in Cell B1.
All this works fine as long as I use the English version of Excel.
Now, a coworker in Poland needs to use the file in a polish Excel version.
Once he opens the file the formula in Cell B1 changes to:
=TEKST(A2;"YYYY-MM-DD")
This formula gives back an error because in Poland instead of YYYY-MM-DD you need to use RRRR-MM-DD.
Therefore, I am wondering if it is somehow possible to make this text formatting international so no matter in which language your Excel is set up the formula is working?
If the only problem is sharing it with your Polish co-worker, then you can simply use the international placeholder "e" to replace "YYYY":
=TEXT(A1,"e-MM-DD")
Now, while this would work fine for your co-worker in Poland, there are countries where "m" and "d" would also need replacement. If in general we need to return the locale "Y", "M" or "D" equivalent you could create three named formulas using the name manager:
1st: Create name called YT and refer to =INDEX(GET.WORKSPACE(37),19)
2nd: Create name called MT and refer to =INDEX(GET.WORKSPACE(37),20)
3rd: Create name called DT and refer to =INDEX(GET.WORKSPACE(37),21)
Now you can use a reference to these names through:
=TEXT(A1,REPT(YT,4)&"-"&REPT(MT,2)&"-"&REPT(DT,2))
NOTE: Depending on which version of Excel you use it could be necessary to:
Enable Excel 4.0 macros when VBA macros are enabled in the Trust Center
Another option with no macros is to use FORMULATEXT:
In a random cell Z5
=TEXT(123, "foo")
Then in your desired cell C1
=TEXT(A1,IF(ISERROR(SEARCH("TEKST", FORMULATEXT(Z5)), "YYYY", "RRRR") & "-MM-DD")
This works because the formula of the random cell will be updated to say TEKST in polish and you can just spot that happening. Obviously the other method is more robust to any country but this requires no settings to be changed.
Bigger:
=TEXT(
A1,
IF(
ISERROR(
SEARCH(
"TEKST",
FORMULATEXT(Z5)
),
"YYYY",
"RRRR"
) & "-MM-DD"
)
The solution is actually simple, surprisingly so.
Whether specifying a formal Custom Format, or specifying a format inside a TEXT() (or TEKST() function), you just add the country-specific code for interpreting the formatting string. So, if a US-Excel version person is writing the formula, and is presumably most conversant in the US English strings to use, and especially if expecting the users to be US-Excel version users, he would write it as:
=TEXT(A1,"[$-en-US]YYYY-MM-DD")
Every version of Excel will then use the US English set of formatting string variables in interpreting the formatting string that follows the [$-en-US]. Since the string is perfectly valid in US English Excel, it will form the date properly and "textify" it as demanded. No error will be produced.
I cannot test a nuance here, that of whether Excel of a different language version will insert itself into the middle here and take the date as the string formats it, and map it to the particular language's names for months, but that is not asked for in the poster's question so... I have the feeling it will not and so one might need to do further work to make the Polish user happiest. If month names were used instead of month numbers.
But the key element of generating a correct numeric date display with no possibility — none at all — of an #ERROR! result rendering things ugly and useless will absolutely be accomplished with no great effort at all.

Some dates recognized as dates, some dates not recognized. Why?

Here is a list of dates:
04-22-11
12-19-11
11-04-11
12-08-11
09-27-11
09-27-11
04-01-11
When you copy this list in Excel, some of them are recognized as dates, others not, in the following manner:
04-22-11
12-19-11
11-04-11 (date)
12-08-11 (date)
09-27-11
09-27-11
04-01-11 (date)
Does anyone know why? And how to force Excel to recognize all list items as dates?
Many thanks!
It is caused by Excel auto-recognizing/formatting the cell contents, but in unclear/inconsistent ways.
Fixing it is not that hard...
Check out this forum post:
http://www.pcreview.co.uk/forums/excel-not-recognizing-dates-dates-t3139469.html
The steps in short:
Select only the column of "dates"
Click Data > Text to Columns
Click Next
Click Next
In step 3 of the wizard, check "Date" under Col data format, then
choose: "DMY" from the droplist.
Click Finish
This is caused by the regional settings of your computer.
When you paste data into excel it is only a bunch of strings (not dates).
Excel has some logic in it to recognize your current data formats as well as a few similar date formats or obvious date formats where it can assume it is a date. When it is able to match your pasted in data to a valid date then it will format it as a date in the cell it is in.
Your specific example is due to your list of dates is formatted as "m/d/yy" which is US format. it pastes correctly in my excel because I have my regional setting set to "US English" (even though I'm Canadian :) )
If you system is set to Canadian English/French format then it will expect "d/m/yy" format and not recognize any date where the month is > 13.
The best way to import data, that contains dates, into excel is to copy it in this format.
2011-04-22
2011-12-19
2011-11-04
2011-12-08
2011-09-27
2011-09-27
2011-04-01
Which is "yyyy-MM-dd", this format is recognized the same way on every computer I have ever seen (is often refered to as ODBC format or Standard format) where the units are always from greatest to least weight ("yyyy-MM-dd HH:mm:ss.fff") another side effect is it will sort correctly as a string.
To avoid swaping your regional settings back and forth you may consider writting a macro in excel to paste the data in. a simple popup format and some basic logic to reformat the dates would not be too difficult.
In your case it is probably taking them in DD-MM-YY format, not MM-DD-YY.
The quickest and easiest way to fix this is to do a find and replace on your date seperator, with the same separator.
For example in this case Find "-" and Replace with "-", not sure why this works but you will find all dates are right-aligned as they should be after doing this.
Here is what worked for me. I highlighted the column with all my dates. Under the Data tab, I selected 'text to columns' and selected the 'Delimited' box, I hit next and finish. Although it didn't seem like anything changed, Excel now read the column as dates and I was able to sort by dates.
The simplest solution is to put yy,mm,dd into the date() formula by first extracting them with left(), mid() and right(). In this case, assuming your input date is in A1:
=date(right(A1,2)+100,left(A1,2),mid(A1,4,2))
Explanation of above:
=right(A1,2) gets the last two digits in the cell (yy). We add 100 because it defaults to 1911 instead 2011 (omit +100 if it doesn't do that on yours)
=left(A1,2) gets the first two digits in the cell (mm).
=mid(A1,4,2) gets 2 digits in the middle of the cell, starting at 4th digit (dd).
Why this happens in the first place:
I come across this problem all the time when I import Canadian bank data into excel. In short, your input date format does not match your regional settings.
Seems your setting mean Excel wants date input as either DD-MM-YY or YY-MM-DD, but your input data is formatted as MM-DD-YY.
So, excel sees your days as months and vice-versa, which means any date with day below 12 will be recognized as a date, BUT THE WRONG DATE (month and day reversed) and any date with day above 12 won't be recognized as a date at all, because Excel sees the day as a 13th+ month.
Unfortunately, you can't just change the formatting, because Excel has already locked those day/month assignments in place, and you just end up moving what Excel THINKS are days and months around visually, not reassigning them.
Frankly, it is surprising to me there is not a date-reverse tool in excel, because I would think this happens all the time. But the formula above does it pretty simply.
NOTE: if your dates don't have leading zeros (i.e. 4/8/11 vs 04/08/12) it gets trickier because you have to extract different amounts of digits depending on the date (i.e. 4/9/11 vs 4/10/11). You then have to build a couple if statements in your formula. Gross.
Here is what worked for me on a mm/dd/yyyy format:
=DATE(VALUE(RIGHT(A1,4)),VALUE(LEFT(A1,2)),VALUE(MID(A1,4,2)))
Convert the cell with the formula to date format and drag the formula down.
Right-click on the column header and select Format Cells, the chose Date and select the desired date format. Those that are not recognized are ambiguous, and as such not interpreted as anything but that is resolved after applying formatting to the column. Note that for me, in Excel 2002 SP3, the dates given above are automatically and correctly interpreted as dates when pasting.
A workaround for this problem consists in temporarily changing your regional settings, so the date format of the CSV imported file "matches" the regional settings one.
Open Office seems to work in a similar way for that issue, see: http://www.oooforum.org/forum/viewtopic.phtml?t=85898
I come across this problem when I tried to convert to Australian date format in excel. I split the cell with delimiter and used the following code from split cells then altered the issue areas.
=date(dd,mm,yy)

Resources