Full Version: Calculate time based off of a variable.
UtterAccess Forums > Microsoft® Access > Access Date + Time
Is it possible to use a variable to calculate current time in a different timezone
I'm creating a database for Overseas Contact information
I would like to display the local time for each location.
I have a field displaying a Time difference populated from a form query
I would like to use that data to dynamically adjust the DateAdd function
I.E. NORMAL =DateAdd("h",6,[TIME])
What I want to do =DateAdd("h","TimeDiff",[TIME])
Dim TimeDiff as Integer
Dim LocalTime as Date
TimeDiff = Me.txtTimeDifference ' where txttimeDifference is the control on your form
LocalTime = DateAdd("h",TimeDiff ,[TIME])
Me.TxtLocalTime = LocalTime
For some reason I'm really struggling with this. I completely understand the logic behind it but I just can't seem to figure it out.
The control source for the time difference value is in fact "TimeZone" In a table named MissionData
The control source for the Local Time is "MissionTime"
THere is what I have......be gentle I rarely use access
Option Compare Database
Dim TimeDiff As Integer
Dim LocalTime As Date
Private Sub Form_load()
TimeDiff = Me.TimeZone ' where txttimeDifference is the control on your form
LocalTime = DateAdd("h", TimeDiff, [TIME])
Me.MissionTime = LocalTime
Oreally appreciate the assistance.
Is Me.TimeZone the name of a control on the form?
Is the control source for Me.TimeZone the field in the table named "MissionData"?
IS TimeZone an integer or a text datatype?
So i'm clear what does the "me." refer to? Most of my Access knowledge is self taught so I'm not solid on industry standards....
The field "TimeZone" on the MissionData table is an integer....at least it is now.
The TimeZone text box in my Form is populated by the TimeZone field in the MissionData table.
Me is a reserved word in Access, it refers to the object in which the code appears. In this case, the form.
That is not working? Are you getting an error? Where did you place the code?
I get

"You can't assign a value to this object."

Then in the debugger the "Me.MissionTime = LocalTime" Line is highlighted

---------after double-checking things for the 11th time
UGH.....I forgot to remove the old "=dateadd....." code from the control source in the text box properties.

Sorry about that...thanks for your patience.

Umm new question

The date shows up as 12/31/1899
Oassume it is generating times based off of my system time..the DB is not networked yet.

Edit -----12/31/1899
Edited by: ineedacatscan on Fri Dec 30 19:41:15 EST 2005.
"double-checking things for the 11th time" You're not the first person to have that happen, believe me.
think the problem may be in the way the format property of the field is defined. It should be "Medium Time" or "Long Time", depending on how you want it to look.
Currently it is set to general date....
deally I would like it to display the date as well
However at this point I'm willing to leave it alone if there is no easy way to do it.
Thanks for all the help
I see, you want to display date AND time, not just time. That's just a little different from time alone.
Is the original value, [Time] defined as a general date also?
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.