German locale and LS Format incompatible?

I have a piece of simple LS code that is working all over the world except in German locales (where the date format chosen is dd.mm.yyyy).

The script looks like this …

EventDate=Format$(StartDate.dateOnly,“mm”)+“/”+Format$(StartDate.dateOnly,“dd”)+“/”+Format$(StartDate.dateOnly,“yyyy”)

the purpose of this is to get the date into format mm/dd/yyyy, but in Germany, this somehow always equates to EventDate of 12/31/9999

I have run in debug, and variable StartDate contains a valid date. Also, this code is running on every other locale without problem.

Can anyone help me.

Subject: German locale and LS Format incompatible?

StartDate.dateOnly returns a string according to the Designer Help, not a variant of type date. So the Format function does not do what you want.

Use StartDate.LSLocalTime instead of StartDate.DateOnly in your formula.

Hope this helps.

Subject: RE: German locale and LS Format incompatible?

Marleen, your fix works, but does not explain why the Format function works for all locales other than Germany. It cannot be that the DateOnly returns a string, because then the Format command would fail in all locales since the others are also returning DateOnly strings.

Also, I found another way of fixing it - instead of using a new DateTime object, I used my old code to get the DateOnly directly from the document object, and now it works fine.

So, there must be a bug in Format.

Subject: RE: German locale and LS Format incompatible?

DateOnly does return a String (formatted as a Short date according to the system settings), but Format should be able to interpret the string and Cdat it before formatting. It doesn’t always, though. Using LSLocalTime instead gets around the problem by avoiding two conversions.

Subject: RE: German locale and LS Format incompatible?

but does not explain why the Format function
works for all locales other than Germany

I guess that is because the German format uses dots between the parts of the
date. I noticed the “/” and the “-” are interchangeable when recognising dates,
the dots may not be.
I did not test it, but because of the dots the German date may be interpreted
as a b>number] instead of a date.

Subject: RE: German locale and LS Format incompatible?

Try Format(StartDate.dateOnly, “mm/dd/yyyy”) instead.

Subject: RE: German locale and LS Format incompatible?

No - still get EventDate as 12/31/9999.

StartDate has “29.06.2005” in all of the built-in components (DateOnly, GMTTIME, LocalTime, LSLocalTime etc).