We help IT Professionals succeed at work.

VB Format (Date) function gives German Date with English Regional Options

Louis01
Louis01 asked
on
2,401 Views
Last Modified: 2008-02-01
Hi

I have come accross an interesting feature / bug in VB and could not find any information regarding a solution...
Maybe someone has more knowledge regarding it...

Create (In VB6) a Dll (MyDll) with a class (MyClass) with a method (showDate)
The method should look like this:

Public Function showDate() as string

     showDate = Format(now, "dd mmmm yyyy")

End Function

Compile it and call it in an ASP page
...
Dim oX
set oX = Server.createObject("MyDll.MyClass")
Response.write oX.showDate
...

The machine was originally installed with German Regional Options and other German software...
After that the Regional Settings was changed to English (W2k Server)

The problem is that I expect to see an output of
   11 February 2003 (on 11 Feb 2004)
However, on this server I see
   11 Februar 2003  - GERMAN DATE
                  _    

Anyone ever come accross the same thing?

p.s. FormatDateTime(now, vbLongDate) in ASP works fine

Thanks
Louis
Comment
Watch Question

Commented:
Hi

download this code : http://www.cyberactivex.com/download/InternationalLocales.zip

It will help you a lot to anderstand, and features to your ASP and VB apps
Why dont you just do replace

'April,August,September,November are the same in german so no need to include them.
showDate = Replace(Format(now, "dd mmmm yyyy"),"January","Januar")
showDate = Replace(Format(now, "dd mmmm yyyy"),"February","Februar")
showDate = Replace(Format(now, "dd mmmm yyyy"),"March","März")
showDate = Replace(Format(now, "dd mmmm yyyy"),"May","Mai")
showDate = Replace(Format(now, "dd mmmm yyyy"),"June","Juni")
showDate = Replace(Format(now, "dd mmmm yyyy"),"July","Juli")
showDate = Replace(Format(now, "dd mmmm yyyy"),"October","Oktober")
showDate = Replace(Format(now, "dd mmmm yyyy"),"December","Dezember")
msgbox ShowDate



Good Luck
-Brian


Author

Commented:
Thanks - but I need to solve the problem.

A lot in the system depends on the Format function with a long date type mask returning the month in the language in the Regional options.

The replace method suggested by Brian would work well, but then you would have to apply it for 50 other languages as well, unless this problem is only in switching between german and english locales - but I doubt it.

The system needs to be generic and could work against any language, so catering for incorrect dates is going to be a massive overhead.


>After that the Regional Settings was changed to English (W2k Server)

You need to change the "Gebietsschema" to English, for EACH USER.
Also, check the Date format on the "Date" tab.

The Default/Standard can remain in German (requires a reboot and changes the ascii table, fonts, etc. used).

Your program should be using hard coded dates in US format, or using date variable or date conversion functions. Store dates in the DB always in Date fields, passed in US format, as opposed to using Text fields.

So, no matter the setting for the language, or the settings for the Date/Number formats, CDate(TheDate) and CDbl(TheNumber) will always return the value formated according to those settings:

TextBox1 Input by the user in the date format as set in the system settings.

Dim myDate as Date
'Validate and Assign the input to a date variable
If IsDate(Text1.Text) Then
    myDate = CDate(Text1.Text)
    myDate = myDate  + 10
    MsgBox "The Date in Local Format: " & CStr(myDate)
    MsgBox "The Date in Local Format: " & Format$(myDate, "dd MMM yyyy")
    MsgBox "The Date in Local Format: " & Format$(myDate, "Long Date")

     MsgBox "The Date in US Short Format: " & Format$(myDate, "MM\/dd\/yyyy")

    'Store the Date in the Database:
    'SQL SERVER
    'rsADO.Execute "UPDATE SomeTable SET SomeDateField = '" & Format$(myDate, "MM\/dd\/yyyy") & "'"
    'JET MDB
    'rsADO.Execute "UPDATE SomeTable SET SomeDateField = #" & Format$(myDate, "MM\/dd\/yyyy") & "#"

    'Best is to always use ISO 92 format. Then you are sure to always have the right format:
    'JET MDB
    rsADO.Execute "UPDATE SomeTable SET SomeDateField = #" & Format$(myDate, "yyyy-MM-dd") & "#"


Else
    'Error out
End If



If you adhear to this, then the user can have their system set to any laguage and your program will always display the correct format/wording.


Commented:
>>FormatDateTime(now, vbLongDate) in ASP works fine

Why don't you use this in your dll?

Author

Commented:
I was able to solve the problem myself.

When the system is installed, the following key is created based on the Administrator settings. After this however there is no way to change it except through the registry.

[HKEY_USERS\.Default\Control Panel\International]
"Locale"="00001C09"

Changing this did the trick...

Thank you for your input anyhow....

Anyone know how I go about getting this question resolved though?
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.