Discussion Locked

how can i change system date formating

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hello
how can i change the default system date formating ?
to be always like "dd/mm/yyyy"

7 replies

by jlouis45

go to start - settings - control panel. In the control panel you have regional settings(double click and open it) you will will find the last tab as date in date if you see down you have short date and long date change it as per your requirement. If it is not there you can just time the format you want. Save and restart system thats it.

by khalid

I mean in Visual Basic
the code i can write to change the system date formating
i'm sorry if my question is not ready

by vinnyd

There is no Global setting in VB to make the date that format.

Each object like a text box or data grid has its own format property for the object that can set a date to the format that you want.

It can also be done under program control usingthe format(date,formatstring) statement.

by sl-campbell

The below will change the short date format but all other settings can be also changed.
'First Declare the follow in the declarations section of a public module:

Public Const REG_SZ As Long = 1

Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, _
ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, hKeyHandle As Long) As Long

Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long

Private Declare Function RegSetValueExString Lib "advapi32.dll" Alias "RegSetValueExA" _
(ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, _
ByVal dwType As Long, ByVal lpValue As String, ByVal cbData As Long) As Long

Then add the following sub:

Public Sub SetRegKeyValue(sKeyName As String, sValueName As String, _
vValueSetting As Variant)

Const REG_SZ As Long = 1
Const HKEY_CURRENT_USER = &H80000001
Const KEY_ALL_ACCESS = &H3F

Dim lRetVal As Long 'result of the SetValueEx function
Dim hKey As Long 'handle of open key
Dim sValue As String 'String holder for vValueSetting to use in RegSetValueExString (REG_SZ)

'open the specified key
lRetVal = RegOpenKeyEx(HKEY_CURRENT_USER, sKeyName, 0, KEY_ALL_ACCESS, hKey)

sValue = vValue & Chr$(0)
lRetVal = RegSetValueExString(hKey, sValueName, 0&, REG_SZ , vValueSetting, Len(vValueSetting))

RegCloseKey (hKey)

End Sub

'Call the sub like:

Dim sKey As String
Dim sName As String
Dim vValue As Variant

sKey = "Control Panel\International"
sName = "sShortDate"
vValue= "MM.dd.YYYY"

SetRegKeyValue sKey, sName, vValue

PS. There may be some typing errors so if it doesn't work, then send a comment and I'll review it again.

This discussion is closed to new replies.