473,327 Members | 2,069 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

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

18
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
Apr 15 '10 #1

✓ answered by muddasirmunir

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.

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Private Const LOCALE_SDATE = &H1F
  4. Private Const LOCALE_STIMEFORMAT = &H1003
  5.  
  6. Private Const WM_SETTINGCHANGE = &H1A
  7.  
  8. Private Const HWND_BROADCAST = &HFFFF&
  9.  
  10. Private Declare Function SetLocaleInfo Lib "kernel32" Alias "SetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String) As Boolean
  11. 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
  12. Private Declare Function GetSystemDefaultLCID Lib "kernel32" () As Long
  13. 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
  14.  
  15. -----------------------------------
  16. Public Function SetDateTime() As Boolean
  17.  
  18. Dim dwLCID As Long
  19.  
  20. dwLCID = GetSystemDefaultLCID()
  21.  
  22. If SetLocaleInfo(dwLCID, LOCALE_SDATE, "dd-MMM-yyyy") = False Then
  23. SetDateTime = False
  24. Exit Function
  25. End If
  26.  
  27. If SetLocaleInfo(dwLCID, LOCALE_STIMEFORMAT, "HH:mm:ss") = False Then
  28. SetDateTime = False
  29. Exit Function
  30. End If
  31.  
  32. PostMessage HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0
  33.  
  34. SetDateTime = True
  35.  
  36. End Function
  37.  
  38. '***************end of module****************
Source
http://www.dreamincode.net/code/snippet1364.htm

3 4642
MBMSOFT
18
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
Apr 15 '10 #2
muddasirmunir
284 100+
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.

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Private Const LOCALE_SDATE = &H1F
  4. Private Const LOCALE_STIMEFORMAT = &H1003
  5.  
  6. Private Const WM_SETTINGCHANGE = &H1A
  7.  
  8. Private Const HWND_BROADCAST = &HFFFF&
  9.  
  10. Private Declare Function SetLocaleInfo Lib "kernel32" Alias "SetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String) As Boolean
  11. 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
  12. Private Declare Function GetSystemDefaultLCID Lib "kernel32" () As Long
  13. 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
  14.  
  15. -----------------------------------
  16. Public Function SetDateTime() As Boolean
  17.  
  18. Dim dwLCID As Long
  19.  
  20. dwLCID = GetSystemDefaultLCID()
  21.  
  22. If SetLocaleInfo(dwLCID, LOCALE_SDATE, "dd-MMM-yyyy") = False Then
  23. SetDateTime = False
  24. Exit Function
  25. End If
  26.  
  27. If SetLocaleInfo(dwLCID, LOCALE_STIMEFORMAT, "HH:mm:ss") = False Then
  28. SetDateTime = False
  29. Exit Function
  30. End If
  31.  
  32. PostMessage HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0
  33.  
  34. SetDateTime = True
  35.  
  36. End Function
  37.  
  38. '***************end of module****************
Source
http://www.dreamincode.net/code/snippet1364.htm
Apr 18 '10 #3
MBMSOFT
18
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 GetTimeZoneInformation Lib "kernel32" _
(lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long

Public Sub ConvertSysDate()

Dim dwLCID As Long
'
dwLCID = GetSystemDefaultLCID()
'
If SetLocaleInfo(dwLCID, LOCALE_SSHORTDATE, "MM/dd/yyyy") = _
False Then
Exit Sub
End If

PostMessage HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0

End Sub

Call ConvertSysDate

can anyone fix the code?
May 4 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Brian | last post by:
I have 4 sites sharing an account on a server that is in the US Eastern time zone. 3 of those sites are for businesses/persons who live in the same time zone, but one is for a restaurant in the US...
6
by: Thomas Scheiderich | last post by:
I have the following page as test.aspx: *************************************************** <html> <head> <title>Hello and Welcome Page</title> </head> <body> <center> <% Dim CurrentDate As...
3
by: Andrew Poulos | last post by:
I'm updating a db in which I have a column of Date/Time data type. The regional settings here for short date are: day / month / full year eg. 28/4/2005 It's easy enough for me to build a string...
12
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error through an asp.net custom validator, it is as...
7
by: mr.nimz | last post by:
hello, this is antenio. recently i've come to a problem. i got a way through it, somehow, still it left me in a curious state, so i'm posting it here, if i can get an answer from some techy, ...
21
by: Darin | last post by:
I have an applicatoin that works 100% perfect when running on a machine setup for English (United States), but when I change it to Spanish (Mexico), the dates start giving me fits. THe reason is...
10
by: ARC | last post by:
Hello all, General question for back-end database that has numerous date fields where the database will be used in regions that put the month first, and regions that do not. Should I save a...
62
by: Wiretwisterz | last post by:
I am using Microsoft Office XP and I have developed an Access database that is used to schedule conference and training rooms within buildings. I have one main form named "Events" that is used to...
1
by: Madhu Harchandani | last post by:
Hello i am working in a project in which i am using xnat technology in that data is entered through xml files only i need to enter 1000 records .so it is very cumbersome to create...
3
by: Wayne | last post by:
I'm building a bookings database for trucks that among other things captures the TruckName, LoadDate, LoadTime, UnloadDate and UnloadTime. Is there a simple way to prevent double bookings for any...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.