views:

471

answers:

3

Is there a way to get a 2 character day-name of the week such as MO/TU/WE/TH/FR/SA/SU?

Currently I only know of using FormatDateTime():

 "ddd" returns "Fri"
 "dddd" returns "Friday"

The main reason is that I want to obtain localized version of the 1 or 2 character day names:

Say FRIDAY in "ddd" would return:
French Windows = "Vendredi", the 2 char would be "VE", note it's the 1st and 2nd char.
Chinese Windows = "星期五", the char would be "五", note it's the 3rd char.
Japanese Windows = "金曜日", the char would be "金", note it's the 1st char.

Edit1: Currently using Delphi, but i think applies to other languages too.

Edit2: Simply put, I'm looking to obtain the shorter version of "ShortDayName" through the use of some functions or constants, so that I don't have to build a table of constants containing the 7 day "Shorter" day names for every possible windows language.

I wonder if such functions really exist.
Maybe the calendar 1 or 2 char day names in Outlook are hard-coded themselves, right?

+2  A: 

Click Here

Depicts the standards in custom date formatting.

You may also use the 'ddd' standard and trim it.

So, which of the things presented on that page gives him anything more than what he already has? Specifically, which part of that page tells how to get two-character day abbreviations? I only see the "ddd" date format, which given a shortened form of unspecified length, which `FormatDateTime` already does.
Rob Kennedy
Stating the available standards. I did not state on how to alter the standard. I'll edit my post.
A: 

Delphi's routines does nothing special - they just ask OS. Here is how to to it: Retrieving Time and Date Information. I looked through MSDNs docs and found this.

Note, that there is no really such thing as "2 character day-name" or "3 character day-name" here. There are: native ("long" in Delphi), abbreviated ("short" in Delphi) or short (Vista and above, not present in Delphi) formats.

For example, abbreviated name of the day of the week for Monday: Mon (3 chars, en-US), Пн (2 chars, ru-RU).

So, you probably look for LOCALE_SSHORTESTDAYNAMEX format (which is called "short" by MSDN and doesn't appear in Delphi), but it is availavle only on Vista and above.

For example, the following code:

const
  LOCALE_SSHORTESTDAYNAME1 = $60;

procedure TForm1.Button1Click(Sender: TObject);
begin
  SetThreadLocale($409);
  ShowMessage(
    GetLocaleStr(GetThreadLocale, LOCALE_SSHORTESTDAYNAME1, '') + #13#10 +
    GetLocaleStr(GetThreadLocale, LOCALE_SABBREVDAYNAME1, '')
             );
end;

will show you:

Mo

Mon

But doing this for Russian will output:

Пн

Пн

Hope my edits make answer more clear ;)

Alexander
It's not that the Delphi functions do *nothing*. That's obviously false. They do nothing *special*. They just use the locale strings defined by the OS.
Rob Kennedy
Thanks, I've corrected my answer. Probably my English isn't good ;)
Alexander
Alexander, seems like it is what I was looking for. But I cannot test it since I don't own any Vista, anyone tried this?
Atlas
The examples are actual output on my Vista. Sadly, on XP the first line will be empty.
Alexander
+2  A: 

You can get the local names for the days of the week with ShortDayNames and LongDayNames, and you can use DayOfWeek to get the numeric value for the day.

ShortDayNames[Index]; //Returns Fri

or

LongDayNames[Index]; //Returns Friday

The only way I know to shorten them to two chars would be to trim the resulting string

LeftStr(LongDayNames[Index],2);//Returns Fr

So today's Day would be

LeftStr(LongDayNames[DayOfWeek(date)],2); //Returns Fr
Re0sless