Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Bug in Delphi (StrToDate)?

860 views
Skip to first unread message

Tobias Mueller

unread,
Dec 24, 2001, 8:48:30 PM12/24/01
to
Hi,

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".


Bruce Roberts

unread,
Dec 24, 2001, 11:45:05 PM12/24/01
to

"Tobias Mueller" <tob...@winkfz.de> wrote in message
news:3c27da82_2@dnews...

> Hi,
>
> 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.

> 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.

Mike Orriss (TeamB)

unread,
Dec 25, 2001, 3:39:13 AM12/25/01
to
In article <3c27da82_2@dnews>, Tobias Mueller wrote:
> - Set the "Short date format" in the Regional Options in Windows|Control
> Panel to dd-MMM-yyyy
>

Not advisable. You will get problems if setting month to more than two
characters.


Mike Orriss (TeamB and DevExpress)


Tobias Mueller

unread,
Dec 25, 2001, 6:45:14 AM12/25/01
to
Hi Mike,

> 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)


Tobias Mueller

unread,
Dec 25, 2001, 6:43:55 AM12/25/01
to
> StrToDate is working as documented.
In the help file it's mentioned that MM/DD/YY, DD/MM/YY and YY/MM/DD are
allowed values for ShortDateFormat. But isn't that a "limitation", since
Windows actually does support a width range of other settings?

> 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)

Rafael Santini

unread,
Dec 25, 2001, 11:34:28 AM12/25/01
to
Yes.

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...

Tobias Mueller

unread,
Dec 25, 2001, 5:27:38 PM12/25/01
to
Hi Rafael,

> 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)


Marjan Venema

unread,
Dec 26, 2001, 4:41:09 AM12/26/01
to
> > 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.

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


Tobias Mueller

unread,
Dec 26, 2001, 5:21:16 PM12/26/01
to
yup thanks. Sorry, missed that one.

Hopefully, everyone who ever build a component used this technique ;)

- tobias (tob...@winkfz.de)


Gokcan Meta

unread,
Sep 4, 2020, 5:06:06 AM9/4/20
to
25 Aralık 2001 Salı tarihinde saat 13:43:55 UTC+2 itibarıyla Tobias Mueller şunları yazdı:
Thank u so much Tobias :) This information has helped me a lot!!! year: 2020 hahahah
0 new messages