Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to determine System Date Format

Status
Not open for further replies.

RussellMorton

Programmer
Feb 17, 2003
10
US
How can I find out if the system date format is MM/DD or DD/MM ????
 
I think it depends on the country that you live in for instance I am in England so it would be DD/MM/YY but America would be MM/DD/YY I think but could be wrong on this.
 
Also Couldn’t you look in BIOS Just to see the format?
 
This is controlled by the locale in regional options/settings in control panel. I believe you can get it from the registry but I recall something like this works -

If CDate("01/12/2000") = 36537 Then
Debug.Print "format is mm/dd"
Else
Debug.Print "format is dd/mm"
End If

Hope it helps.



 
Or you could use api:

Declaration:
[tt]
Const LOCALE_USER_DEFAULT = &H400
Private Declare Function GetLocaleInfo Lib "kernel32" Alias "GetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String, ByVal cchData As Long) As Long


Public Function GetInfo(ByVal lInfo As Long) As String
Dim Buffer As String, Ret As String
Buffer = String$(256, 0)
Ret = GetLocaleInfo(LOCALE_USER_DEFAULT, lInfo, Buffer, Len(Buffer))
If Ret > 0 Then
GetInfo = Left$(Buffer, Ret - 1)
Else
GetInfo = ""
End If
End Function
[/tt]

Then just get it with:

[tt] MsgBox GetInfo(32)[/tt]


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Or just use:

If Month("01-02-03") = 1 Then
strFormat ="MM/DD/yyyy"
else Month("01-02-03") = 2 Then
strFormat = "DD/MM/yyyy"
End if

You can extend this using the Day() and Year() functions to return the EXACT format, just in case the format is something like "yyyy/MM/DD"

I myself use johnwm's method as under:
thread222-238060 which explains a little bit what is being done, and returns the Short and Long formats.

To return the Short date in johnwm's example, use this:

Const LOCALE_SSHORTDATE As Long = &H1F
Const LOCALE_SLONGDATE As Long = &H20

GetInfo(LOCALE_SSHORTDATE)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top