System date Format

razaqad

Raza
Local time
Today, 17:24
Joined
Mar 12, 2006
Messages
83
how can i find out through vb code that what is set asthe "short date format" for system.

(ie for "winxp" goto control panel > regional settings > regional options > customize > Date > short date format )


i want to find out that the date format is dd/mm/yy or mm/dd/yy.

It would be also helpful if you tell me how to change the system date format
through code.

Would that be different for win 98, win me, win xp , win 2003 , win 2000, and win nt


Thank you
 
It would be also helpful if you tell me how to change the system date format
through code.

You try changing the sytem date on my PC through code and at lest two security systems are going to start popping up alarms.
I have my settings the way I wan't them any program that tries changing them will get short shift!

Why do you want to know the format anyway? it is only a display format and you can control how Access displays dates independently.

Peter
 
there are some time date calculation functions that need the system date to be formated in a specific format.

i have found the code and it works fine on winxp:
Private Const LOCALE_SSHORTDATE = &H1F
Private Const WM_SETTINGCHANGE = &H1A
'same as the old WM_WININICHANGE
Private Const HWND_BROADCAST = &HFFFF&

Private Declare Function SetLocaleInfo Lib "kernel32" Alias _
"SetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As _
Long, ByVal lpLCData As String) As Boolean
Private Declare Function PostMessage Lib "user32" Alias _
"PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function GetSystemDefaultLCID Lib "kernel32" _
() As Long


Private Sub ChngDateFrmt()
Dim dwLCID As Long
dwLCID = GetSystemDefaultLCID()
If SetLocaleInfo(dwLCID, LOCALE_SSHORTDATE, "dd/MM/yy") = False Then
MsgBox "Failed"
Exit Sub
End If
PostMessage HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0
End Sub





but does this coed work on all versions of windows eg win98 , winme , winNt etc
 
Bat17 said:
Why do you want to know the format anyway? it is only a display format and you can control how Access displays dates independently.
I had an old db program I inherited and it would choke if the systems short date was not set to mm/dd/yyyy when a custom date function calculation was used.
 
razaqad said:
there are some time date calculation functions that need the system date to be formated in a specific format.

i have found the code and it works fine on winxp:
Private Const LOCALE_SSHORTDATE = &H1F
Private Const WM_SETTINGCHANGE = &H1A
'same as the old WM_WININICHANGE
Private Const HWND_BROADCAST = &HFFFF&

Private Declare Function SetLocaleInfo Lib "kernel32" Alias _
"SetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As _
Long, ByVal lpLCData As String) As Boolean
Private Declare Function PostMessage Lib "user32" Alias _
"PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function GetSystemDefaultLCID Lib "kernel32" _
() As Long


Private Sub ChngDateFrmt()
Dim dwLCID As Long
dwLCID = GetSystemDefaultLCID()
If SetLocaleInfo(dwLCID, LOCALE_SSHORTDATE, "dd/MM/yy") = False Then
MsgBox "Failed"
Exit Sub
End If
PostMessage HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0
End Sub





but does this coed work on all versions of windows eg win98 , winme , winNt etc



this code is working perfectly right on winxp. And i can also check the current date fromat without changing.

but i want to know that would this code be compatible on other versions of windows (win98 and above )? i dont have access to win 98 , winnt etc.
 
Format function.

Here's a thought:

When retrieving the current date, use the Format function to mold it into whatever format you require (YYYY-MM-DD, MM/DD/YYYY, MM/DD/YY, DD/MM/YY, DD/MM/YYYY, etc).

Let the Format function handle the transformation of the date from the system format to whatever your code requires.

Example:
MyStr = Format(Date(), "dddd, mmm d yyyy")
 
Last edited:
Me! ... i appreciate your response...
and i already understand it...... actually i had a situation in ehich i needed to change the system date format. and under winxp i am sucessful. I just want to know that does the code i have posted earlier work under win98 and other versions of windows.

anyways thanks for the effort
 

Users who are viewing this thread

Back
Top Bottom