45

i'm automating excel, using the macro system as a guide to what i should do through automation. When i format a column as a date, the macro generated a NumberFormat for the column to be:

[$-409]m/d/yy h:mm AM/PM;@

i'm trying to decipher what this really means. i gather from googling, that the values in the square brackets are a "condition", and that if the condition:

$-409

is met, then it will use the NumberFormat

m/d/yy h:mm AM/PM

if not, it uses the NumberFormat

@

The references i find say that the number format "@" is a Text Placeholder

So my questions are:

  1. What is the conditional $-409 testing? Is it comparing something against -409 (i.e. negative four hundred and nine), and if so, what is the dollar sign it's comparing against?

  2. If the conditional fails, and it resorts to the Text Placeholder "at-sign", what does it show as?

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
  • if you provide examples of the datetime you entered in the cell and how Excel formatted it, that would be helpful – V'rasana Oannes May 21 '09 at 20:06
  • How did you go about formatting the cell by date when you recorded the macro? I just tried the same thing, and the VBA code produced had no conditional portion at all. – e.James May 21 '09 at 20:26

6 Answers6

50

To clarify what others have said:

The [$-409] is a locale code, given in hexadecimal. Prefixing a date with a certain locale code determines what is shown when you use the various date time format codes. For example using the date

November 28, 1973 11:28:13 AM

as an example for the following table:

Format Code  409 (English United States)  804 (Chinese PRC)
===========  ===========================  =================
m            11                           11
mm           11                           11
mmm          Nov                          十一月
mmmm         November                     十一月
d            27                           27
dd           27                           27
ddd          Mon                          二
dddd         Monday                       星期二
y            73                           73
yy           73                           73
yyy          1973                         1973
yyyy         1973                         1973
AM/PM        AM                           上午

So in the end the same format code with two different locale identifiers, gives different results:

[$-409]mmmm dd yyyy  h:mm AM/PM
November 27 1973  11:28 AM


[$-804]mmmm dd yyyy  h:mm AM/PM
十一月 27 1973  11:28 上午

Since finding a list of locale codes is like pulling teeth, here are some references:

Language Identifier Constants and Strings (Primary source, archive.is)

Windows Locale Codes Sorted by Locale (archive.is)

Windows Locale Codes Sorted by Locale (archive.org, archive.is)

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
  • related question, not worth starting my own topic, but you seem to know the subject well... how does Excel understand that in `yyyy-mm-dd hh:mm:ss AM/PM` that the first mm represents months, but the second one minutes? ^?^ – James King Jun 03 '12 at 16:02
  • i would guess they recognize `yyyy` being near one, and `hh` or `ss` near the other. */shrug* – Ian Boyd Jun 04 '12 at 15:48
  • 4
    The [specs](http://www.ecma-international.org/publications/standards/Ecma-376.htm) stipulate that if "m" or "mm" is immediately after "h" or "hh", or immediately before "s" or "ss", then it's interpreted as minutes; otherwise, it's the month. – John Y Jul 01 '15 at 18:52
  • I wonder if/how this also applies to https://stackoverflow.com/q/53948301/11683 where the locale identifier seems to be `,13`/`130000` which does not appear to make sense at the first glance. – GSerg Dec 27 '18 at 18:46
  • 2
    For a more complete list on locale codes, and calendar codes...check out my sources on this answer (which is slightly different)... https://stackoverflow.com/questions/54134729/what-does-the-130000-in-excel-locale-code-130000-mean/54540455#54540455 – IrwinAllen13 Feb 07 '19 at 21:50
13

Naaf and Grant Wagner have neatly answered the question about your $-409, so I'll just fill in the missing part:

The '@' after the semicolon tells Excel how to treat the data if you enter a string instead of a valid date. The @ simply means "place any text here, verbatim".

Some quick examples to illustrate the point:

=TEXT("abc","hh:mm;@")
abc


=TEXT("abc","hh:mm;@@")
abcabc

See this article for a detailed description of the text formatting options.

e.James
  • 116,942
  • 41
  • 177
  • 214
  • I believe you are mistaken, at least in part. Dates in Excel are just stored as number of days since 1900 or 1904; the part after the semicolon is the format to use if the underlying number is negative. – ysth Nov 06 '12 at 22:52
9

This post explains it. Basically 409 is the locale ID for "English - United States". If you used [$-414], for example, then the date would be formatted for "Norwegian (Bokmål)" instead.

My guess for question (2) is that the raw data would be presented as a string instead of being formatted. A quick test would verify this.

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
Naaff
  • 9,213
  • 3
  • 38
  • 43
4

There is a bug in Excel 2007 that changes all general formats to a [$-409] type date format.
Normally, use of the [$-409] is an okay format.
There is no fix for the bug yet provided by Microsoft. This Bug normally happens in Large and Shared Excel workbooks.

If you ever have the experience where all of your general formats change to dates try going to Cell Styles, Right clicking on Normal and modifying normal back to general. It will tell you in the box the format type for Normal. This is the bug as it typically should be 'general' not some verison of [$-409].

I ended up having to delete the format from the workbook entirely. The Workbook must be unshared to do this. To delete the Format [$-409] identified above under the "Normal" cell type from the workbook, Right click on a cell, select Custom, scroll until you find the [$-409] format type identified above, delete then all formats will return back to what is called general.

  • 1
    it's not a bug, it's the culture code. 409 is United States, 816 is Portugal. You can check with =TEXT(TODAY(), "[$-816]d \d\e mmmm \d\e yyyy") returns current date like "4 de abril de 2018". If you use =TEXT(TODAY(), "[$-409]d \d\e mmmm \d\e yyyy") it will return "4 de April de 2018". abril is the portuguese word for April. – Pedro Polonia Apr 04 '18 at 08:57
  • Techincally `-0409` i just the language code. If you want to change the date format, then you must change the calendar code, which is different. Check out my answer on this one - https://stackoverflow.com/questions/54134729/what-does-the-130000-in-excel-locale-code-130000-mean/54540455#54540455 – IrwinAllen13 Feb 07 '19 at 21:48
3

[$-409] does not appear to be a condition. It seems to be a Locale code.

If I format a cell with a Custom format of [$-409]m/d/yy h:mm AM/PM;@, enter a date: 1/1/9, then view the formatting for the cell, I see a Date format of m/d/yy h:mm AM/PM with a Locale (location) of English (United States).

If you change the format to something like [$-439]m/d/yy h:mm AM/PM;@ you'll see the contents of the cell in another language.

I'm not sure about @. It might indicate how to display the date if the correct font or locale is not available.

Here is list of Locale IDs Assigned by Microsoft.

Grant Wagner
  • 25,263
  • 7
  • 54
  • 64
  • The @ is a text placeholder. See my response for the dirty details, and thank you for the link to the Locale IDs. – e.James May 21 '09 at 23:04
1

TLDR: What goes between the $ and - in the locale code defines the currency symbol to use in the number format(more specifically nothing for: [$-409]).

Excel is old tech, so when you start digging into the details you'll start to notice some of the "baggage"(a.k.a. tech-debt) that's leftover from a bygone era, and this appears to be one of those things that has not aged very well in the documentation.

Here's the story as best as I was able to piece together:

in section 2.1.378 item b. of MS-OE376 - v20160623 it mentions:

NFPartLocaleID = ASCII-LEFT-SQUARE-BRACKET ASCII-DOLLAR-SIGN 1*UTF16-ANY [ASCII-HYPHEN-MINUS 3*8ASCII-DIGIT-HEXADECIMAL] ASCII-RIGHT-SQUARE-BRACKET

in Part 4 section 3.8.31 of the ECMA-376 (1st Edition / Dec 2006) specification, towards the end there is a table of International Considerations in which the final entry mentions:

Format Code Description
[$USD-409]

Specifies currency and locale/date system/number system information.

Syntax is [$<Currency String>-<language info>]. Currency string is a string to use as a currency symbol. Language info is a 32-bit value entered in hexidecimal format.

Language info format (byte 3 is most significant byte):
Bytes 0,1: 16-bit Language ID (LID).
Byte 2: Calendar type. High bit indicates that input is parsed using specified calendar.
Byte 3: Number system type. High bit indicates that input is parsed using specified number system.

next going to the remnants of the MSDN tech doc's to try and find out what is a locale ID, it mentions some insights into what the structure of a 32-bit LCID used to be back when Excel was still a Win32 app:

     [$-409] NFPartLocaleID
 0x00000409  <Language info>
          0          0          0          0          0          4          0          9
       0000       0000       0000       0000       0000       0100       0000       1001
+----------+----------+----------+----------+----------+----------+----------+----------+
                     3                     2                     1                     0  byte
+---------------------------------------------------------------------------------------+
|                                   Locale Identifier                                   |
+--------------------------------+----------+-------------------------------------------+
|            Reserved            | Sort ID  |                Language ID                |
+--------------------------------+----------+---------------------+---------------------+
 31                            20 19      16|   SubLanguage ID    | Primary Language ID |
                                            +---------------------+---------------------+
                                             15                 10 9                   0  bit

finally going to MS-LCID v15.0 in section 2.2 there is a Language ID(2 bytes) table that mentions:

Language ID Language tag
0x0409 en-US

So to me the [$-409] in [$-409]d h:mm:ss would read as en-US with no currency symbol defined that formats 12.34 as 12 8:09:36, whereas [$$-409] 0.00 or [$USD-409] 0.00 which would format it as $ 12.34 and USD 12.34 respectively.

Gregor y
  • 1,762
  • 15
  • 22