I don't exactly know wether I'm doing something wrong or if there's a bug in
Delphi so I post some sample code here. If you have any ideas on what may go
wrong please let me know.
Steps to reproduce:
-------------------------------
- Set the "Date separator" in the Regional Options in Windows|Control Panel
to "-"
- Set the "Short date format" in the Regional Options in Windows|Control
Panel to dd-MMM-yyyy
- Click OK
The "Short date sample" should look like "25-Dec-2001"
Now create a simple application in Delphi which includes just one form and
one button on it. Type in the following code for the OnClick event handler
of the button:
StrToDate(DateToStr(Date));
That's all. Everytime I try this simple code I get an exception that
24-Dec-2001 is not a valid date. Personally I would say that StrToDate
should inverse DateToStr and should work like + does to -:
1+1-1 = 1
1-1+1 = 1
because - is the inverse to +.
Thanks for any information on this topic.
- tobias (tob...@winkfz.de)
P.S.: I tried Delphi 4,5,6 on Windows 2000(de),XP(en).
P.P.S: Based on the above, there are also errors if you try to work with the
BDE with the above mentioned type of "Short date format".
> StrToDate(DateToStr(Date));
>
> That's all. Everytime I try this simple code I get an exception that
> 24-Dec-2001 is not a valid date. Personally I would say that StrToDate
> should inverse DateToStr and should work like + does to -:
StrToDate is working as documented. The function is not the inverse of
DateToStr.
Not advisable. You will get problems if setting month to more than two
characters.
Mike Orriss (TeamB and DevExpress)
> Not advisable. You will get problems if setting month to more than two
> characters.
Is there any workaround for this problem?
Thanks,
- tobias (tob...@winkfz.de)
> The function is not the inverse of DateToStr.
From the help file (translated by me since I have the German help files):
- StrToDate: The function StrToDate converts a string to a Datevalue*
- DateToStr: The function DateToStr converts a variable of type TDateTime
into a string.
[*] Datavalue means variable of type TDateTime.
Doesn't that mean StrToDate -> converts string to date; and DateToStr ->
converts DateToStr?
Do you have any advice what should be used instead of StrToDate which is
able to handle different ShortDateFormats (as Windows is)?
Thanks,
- tobias (tob...@winkfz.de)
See this code:
var
OldShortDateFormat: String;
begin
OldShortDateFormat := ShortDateFormat;
ShortDateFormat := 'dd-mm-yyyy';
StrToDate(DateToStr(Date));
ShortDateFormat := OldShortDateFormat;
end;
Regards,
--
/*
* Rafael Santini
* E-Mail: rafael...@terra.com.br
* ICQ 54152945
* Floripa/SC
*/
"Tobias Mueller" <tob...@winkfz.de> escreveu na mensagem
news:3c28665a$1_2@dnews...
> ShortDateFormat := 'dd-mm-yyyy';
that's exactly what I thought first. But since I live in Germany I would set
ShortDateFormat to dd.mm.yyyy because that's the way we write a date. Now
whenever I present a date to the user it will have the format specified by
me (e.g. German). Customers in the US would be a bit upset if I print
24.12.2001 on their invoices since they are used to see 12/24/2001.
Do you have any other ideas? Thanks!
- tobias (tob...@winkfz.de)
I think you missed the
OldShortDateFormat := ShortDateFormat;
and the
ShortDateFormat := OldShortDateFormat;
surrounding the explicit assignment of 'dd-mm-yyyy' to the ShortDateFormat.
Marjan
_________________________
Marjan Venema - BJM Software
in...@bjmsoftware.com
http://www.bjmsoftware.com
Hopefully, everyone who ever build a component used this technique ;)
- tobias (tob...@winkfz.de)