I would like to write a method that gives me the 3 letters - representing the day, month, year - from a datetimeformat.
So in en-US culture my desired return values would be (plus the separator)
- d
- M
- y
- /
in de-DE the same method should return
- T (Tag = day)
- M (Monat = month)
- J (Jahr = year)
- . (Separator)
I had a look into the DateTimeFormatInfo class form CurrentCulture but could only find the separator do you have any idea how I can get the rest?
var culture = Thread.CurrentThread.CurrentCulture;
Console.WriteLine(culture.DateTimeFormat.DateSeparator);
I need this because the TEXT function inside Excel doesn't accept the format from the InvariantCulture and only handles it from the currentculture.
So something like this isn't valid in german Excel version:
=TEXT(NOW();"dd.MM.yyyy")
this needs to be set with
=TEXT(NOW();"TT.MM.JJJJ")
(it doesn't matter if its done with VBA, it doesn't get translated) You can have a look at the following http://www.rondebruin.nl/win/s9/win013.htm
The string format can be anything since the user can input it as he likes and I need to translate it to the current culture.
You can do this in VBA: DateTimeStrings will return an array of the date codes and separator.
EDIT: I'm not sure how you want to use this, but, for example, to insert a formula similar to what you have above, (eg:
=TEXT(A1,"dd/mm/yyy")
in B1 and in the appropriate language, you could select A1 and run the following macro:=============================================
===================================================