Set TimeZone for Date

patorodriguez

New member
Local time
Today, 08:01
Joined
Sep 29, 2016
Messages
2
How could I always get CST Time Zone when posting Date on Update Date field within Access table. Users access DB from different locations (TimeZones) in US to update Back End DB tables. Hopefully there is simple VB code to accomplish this. Thanks in advance.
 
I think you could add a calculated field in the backend table and use dateadd to adjust the time zone. For example in the expression below the time is adjusted to be two hours later than the time of the computer.

Code:
TimeValue(DateAdd("h",2,now()))

Of course if the backend is located in the CST Time Zone then you wouldn't need the DateAdd function.
 
Welcome to the site. I moved your thread to a more appropriate forum.
 
Yes, but I need to know TimeZone of computer user is trying to update the backend. Application is utilizing Date/Time of user running the application.
 
Yes, but I need to know TimeZone of computer user is trying to update the backend. Application is utilizing Date/Time of user running the application.

Sorry sometimes I forget that the backend is just a dumb file.

It seems you will have to use the GetTimeZoneInformation function to get the time zone information. The following is some code that was extracted and simplified from the code at this Web site. To use this code you would put it in a standard (non form) module.


Code:
Type SYSTEMTIME
  wYear As Integer
  wMonth As Integer
  wDayOfWeek As Integer
  wDay As Integer
  wHour As Integer
  wMinute As Integer
  wSecond As Integer
  wMilliseconds As Integer
End Type

Type TIME_ZONE_INFORMATION
  Bias As Long
  StandardName(31) As Integer
  StandardDate As SYSTEMTIME
  StandardBias As Long
  DaylightName(31) As Integer
  DaylightDate As SYSTEMTIME
  DaylightBias As Long
End Type

Declare Function GetTimeZoneInformation Lib "kernel32" _
  (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long

Public Function GetCTS() As Date

Dim lngRet As Long
Dim TZI As TIME_ZONE_INFORMATION

lngRet = GetTimeZoneInformation(TZI)

GetCTS = DateAdd("n", [COLOR="Blue"]TZI.Bias[/COLOR] - 300, Now)

        
End Function

The TZI.Bias is this function is the time difference in minutes from the computer running the code and UTC. By subtracting 300 minutes the GetCTS produces the CTS Date/Time but I oversimplified the code just to demonstrate its feasibility. This needs work as it doesn't consider daylight savings time. I believe the code full code at that Web site does that.
 

Users who are viewing this thread

Back
Top Bottom