I am trying to get the correct DateSeparator
when the system locale is set to Cenz Republic. The current date is formatted as 9.3.2017
, but DateSeparator
is always '/'
instead of '.'
. What can I do to get the correct date separator?
Asked
Active
Viewed 956 times
-2

Remy Lebeau
- 555,201
- 31
- 458
- 770

user7424581
- 43
- 7
-
1Can you show a little MVCE – Alec Mar 09 '17 at 06:29
-
my seetings : Control panel->Region and language-> format -> Czech Republic . Now short date format is d.M.yyyy here separator is . but when i put dateseparator in messagebox like Messagebox(dateseparator) ; and run it, it will display '/'(which is default separator of dateseparator) instead of '.' as separator – user7424581 Mar 09 '17 at 06:42
-
`DateSeparator` is initialized to whatever the user's current locale says it is, according to [`GetLocaleInfo()`](https://msdn.microsoft.com/en-us/library/windows/desktop/dd318101.aspx) for [`LOCALE_SDATE`](https://msdn.microsoft.com/en-us/library/windows/desktop/dd373837.aspx). – Remy Lebeau Mar 09 '17 at 06:56
-
1Since `DateSeparator` is a global variable in D5, it can be changed by some other part of your program. – LU RD Mar 09 '17 at 07:56
-
[mcve] means someone has a much better chance of helping you. Of course if don't really want help.... – Disillusioned Mar 09 '17 at 11:15
1 Answers
1
Regarding date presentations there are several separate global variables affecting the output. You mention two of them:
`DateSeparator: Char;` (initialized from registry with reference `LOCALE_SDATE`)
`ShortDateFormat: string;` (initialized from registry with reference `LOCALE_SSHORTDATE`)
The other ones you can see in the documentation or in code in unit SysUtils
starting on line 490 (in Delphi 7, might be different in Delphi 5).
Since the DateSeparator
and ShortDateFormat
are separate variables, it is possible that you see dates presented correctly according your locale, while the DateSeparator
return an erroneous character.
To rectify, you can assign the correct character to DateSeparator
yourself in your code, but beware if you are using 3rd party libraries, that those might possibly also want to change it.

Tom Brunberg
- 20,312
- 8
- 37
- 54
-
`DateSeparator` is at line 465 of my antique D5 sysutils. Good answer, +1 – MartynA Mar 09 '17 at 12:03
-
I don't think Delphi 5 supports functions taking a `TFormatSettings` record. Everything uses the shared global variables. – Rob Kennedy Mar 09 '17 at 13:47
-
The question asks why the variable does not hold the expected value. That is what is being asked, and that is what an answer needs to speak to. – David Heffernan Mar 09 '17 at 14:19
-
@David The question asks *How to get the correct date separator?* That, together with a why, is what I try to answer (currently verifying if my second point is rubbish) – Tom Brunberg Mar 09 '17 at 14:28
-
@TomBrunberg: I can't see an overload, nor any sign of TFormatSettings anywhere in the D5 source. I guess TFormatSettings must have been a later addition. In that era, myself I always used the SysTools date & time routines in preference to the built-in ones. That was the only code, as I recall where there were no y2k worries. – MartynA Mar 09 '17 at 14:43
-
Thank you @Martyn for digging into it. I remove the second point in my answer. – Tom Brunberg Mar 09 '17 at 14:45
-
Note the [documentation](https://msdn.microsoft.com/en-us/library/windows/desktop/dd373837.aspx) for `LOCALE_SDATE`: "*Character(s) for the date separator. The maximum number of characters allowed for this string is four, including a terminating null character. Windows Vista and later: **This constant is deprecated**. Use `LOCALE_SSHORTDATE` instead. A custom locale might not have a single, uniform separator character. For example, a format such as `"12/31, 2006"` is valid.*" – Remy Lebeau Mar 09 '17 at 20:49