How to prevent from different date/time format on different pc

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MBMSOFT
    New Member
    • Apr 2010
    • 18

    How to prevent from different date/time format on different pc

    Any idea How to prevent from different date/time format on different pc

    I've heard that I should create my own system time function in VBA which will not depend from the local pc system date/time setting

    Regards
  • MBMSOFT
    New Member
    • Apr 2010
    • 18

    #2
    let's say that I've used this format :

    dd.mm.yyyy

    in some certain control

    and the local date format settings is:

    yyyy-mm-dd

    then if I use

    format(ctl,"ww" ) result is false

    or if i've write in table date in one format all further action can be confused after somehow the local date settings had been changed or mdb would be used on other computer

    any idea how to solve this problem

    I need somehow to tell to VB that I use some certain date format instead the local date/time settings, so vb to ignore the local date/time format

    Comment

    • muddasirmunir
      Contributor
      • Jan 2007
      • 284

      #3
      This might help you , at the start of you application change the system date format to you desire on by using this code

      Instructions


      Simply copy and pase the function into your programe and run the function by typing
      SetDateTime at load event or your desired event.
      if you want to change your format to any other type just change
      "dd-MMM-yyyy" as your desired format.

      Code:
      Option Explicit
      
      Private Const LOCALE_SDATE = &H1F
      Private Const LOCALE_STIMEFORMAT = &H1003
      
      Private Const WM_SETTINGCHANGE = &H1A
      
      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 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 SetDateTime() As Boolean
      
      Dim dwLCID As Long
      
      dwLCID = GetSystemDefaultLCID()
      
      If SetLocaleInfo(dwLCID, LOCALE_SDATE, "dd-MMM-yyyy") = False Then
      SetDateTime = False
      Exit Function
      End If
      
      If SetLocaleInfo(dwLCID, LOCALE_STIMEFORMAT, "HH:mm:ss") = False Then
      SetDateTime = False
      Exit Function
      End If
      
      PostMessage HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0
      
      SetDateTime = True
      
      End Function
      
      '***************end of module****************
      Source

      Comment

      • MBMSOFT
        New Member
        • Apr 2010
        • 18

        #4
        thanks... i trie'd it and it works
        But, i'm not sure if it's the best solution that I change the local date settings..
        it should be some way that VB can ignore or convert date format while the application is running..
        I found some code that is doing some conversion but doesn't work as follow:

        Private Declare Function GetTimeZoneInfo rmation Lib "kernel32" _
        (lpTimeZoneInfo rmation As TIME_ZONE_INFOR MATION) As Long

        Public Sub ConvertSysDate( )

        Dim dwLCID As Long
        '
        dwLCID = GetSystemDefaul tLCID()
        '
        If SetLocaleInfo(d wLCID, LOCALE_SSHORTDA TE, "MM/dd/yyyy") = _
        False Then
        Exit Sub
        End If

        PostMessage HWND_BROADCAST, WM_SETTINGCHANG E, 0, 0

        End Sub

        Call ConvertSysDate

        can anyone fix the code?

        Comment

        Working...