Results 1 to 15 of 15
  1. #1
    dniezby is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Apr 2013
    Posts
    183

    Show me a contact's local time?

    Anyone have any idea if there is a way for me to put a live field on a form that shows me my contact's local time?

    Imagine a contact form.

    I want to call that contact, in the top corner of the form is says - CTX Local Time: 9:40pm

    Opps, don't want to call this late.


    Hope it could be done. This would be awesome to have on any contact form application.

    Thanks.

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,535
    You will need a field in your contacts table in which you can put the number of hours they are ahead or behind your own time. Then on your form you would just need a text box with an expression as its Row Source. The expression would use the DateAdd() function and the stored data of hours difference to do the calculation.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    dniezby is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Apr 2013
    Posts
    183
    Quote Originally Posted by Bob Fitz View Post
    You will need a field in your contacts table in which you can put the number of hours they are ahead or behind your own time. Then on your form you would just need a text box with an expression as its Row Source. The expression would use the DateAdd() function and the stored data of hours difference to do the calculation.
    Well, I do have a time zone field on the form. It tells me -6, -5 etc. I'm not familiar with DateAdd


    Sent from my iPhone using Tapatalk

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,535
    For info on DateAdd() search google or Access Help. For example see: https://www.techonthenet.com/access/...te/dateadd.php

    Expression will be something like: =DateAdd("h",[name of your time zone field],Now())
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    dniezby is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Apr 2013
    Posts
    183
    Quote Originally Posted by Bob Fitz View Post
    For info on DateAdd() search google or Access Help. For example see: https://www.techonthenet.com/access/...te/dateadd.php

    Expression will be something like: =DateAdd("h",[name of your time zone field],Now())
    Thanks, this helps a lot.

    So I would put this in a new field or could I use a label?

  6. #6
    dniezby is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Apr 2013
    Posts
    183
    Quote Originally Posted by Bob Fitz View Post
    For info on DateAdd() search google or Access Help. For example see: https://www.techonthenet.com/access/...te/dateadd.php

    Expression will be something like: =DateAdd("h",[name of your time zone field],Now())
    Okay, this - sort of - worked.

    This is what I used :
    Code:
    =DateAdd("h",[Timezone],Now())
    Works great - HOWEVER, it's calculating the wrong column.

    My timezone field uses a lookup from the timezone table. That table is

    ID
    Name (Common name (IE: Central Standard Time) )
    Offset (GMT Offset (IE: -6) )
    Code (Name abbv (IE: CST) )

    In the lookup I show two columns ( Name & Offset ) but I only save the ID

    Using the above mentioned method, it appears to be calculating on the record ID when I need it to calculate on the offset.

    Is there a way to target it to that column OR should I modify the timezone table by getting rid of the ID column and using the Offset column as a primary key and reference?

  7. #7
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,535
    You do not have fields on a form. You have "Controls" that are bound to fields of a table or query. These controls display the data in the query/table. Use an unbound text box and put the expression as the "Control Source" setting of this text box.
    I would set its Enabled property to NO and its Locked property to Yes.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  8. #8
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,535
    Quote Originally Posted by dniezby View Post
    Okay, this - sort of - worked.

    This is what I used :
    Code:
    =DateAdd("h",[Timezone],Now())
    Works great - HOWEVER, it's calculating the wrong column.

    My timezone field uses a lookup from the timezone table. That table is

    ID
    Name (Common name (IE: Central Standard Time) )
    Offset (GMT Offset (IE: -6) )
    Code (Name abbv (IE: CST) )

    In the lookup I show two columns ( Name & Offset ) but I only save the ID

    Using the above mentioned method, it appears to be calculating on the record ID when I need it to calculate on the offset.

    Is there a way to target it to that column OR should I modify the timezone table by getting rid of the ID column and using the Offset column as a primary key and reference?
    I assume that [Timezone] is a combo box. If so, try:
    =DateAdd("h",[Timezone].column(2),Now())
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  9. #9
    dniezby is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Apr 2013
    Posts
    183
    I assume that [Timezone] is a combo box. If so, try:
    =DateAdd("h",[Timezone].column(2),Now())
    That worked-ish.

    It's giving me the time related to my local time but it won't be accurate if the user moves around. I also have to change the way I store the time offset. Right now I'm storing it as an offset to GMT. For example, Central Standard Time is -6...

    I wonder is I could do something like this?

    =DateAdd("h",[Timezone].Column(2)+6,Now())


    Testing it seems to work fine for timezones that are single digit offsets. So, Eastern time = -5 but when I select Hawaii timezone ( -10 ) it's an hour off to the later. It says it's 6am when it's really 5am. Also, I don' t think the +6 part would work if my user was on the East coast or west.

    So, I guess I have to figure out how to return the GMT time first then do the math so that it's accurate no matter where my user is using the application.

  10. #10
    dniezby is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Apr 2013
    Posts
    183
    Okay so here is what I'm thinking.

    I create a new table called "Settings" - In the settings, I have a look up to the timezone table. This way the user could change his / her current timezone through the settings.

    Then I create a Form onLoad event.

    Code:
    Private Sub Form_Load()
    Dim TimeSetting as String
    TimeSetting = DLookup("[timezone]", "settings")
    End Sub
    Then in the "local time" control box I use that formula

    Code:
    =DateAdd ("h",[Timezone].Column(2)+TimeSetting,Now())
    Would that work or did I totally screw up my thinking?

  11. #11
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    It seems to me that as long as the user "moves around" you're chasing your tail.
    The user would have to identify where he/she is in order for the "local time" to be correct.

    If user is in UK today and Canada tomorrow, you need something to identify where the user is at the time to show local time consistently.

    Now, for a quick diversion, if you had a function to "talk" to googleMaps or Earth or some related product, you might be able to determine where the user is (Lat/long or whatever), then use that to identify "Local" timezone.
    User could type in City/country or select from a list....
    Good luck.

  12. #12
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    I have an example I created to work with time zones that might be helpful:

    Time Zones (Click Here)

  13. #13
    dniezby is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Apr 2013
    Posts
    183
    Yeah that's way more intense than I was looking to do. I'm just gonna create. A settings table and set their time zone from there.


    Sent from my iPhone using Tapatalk

  14. #14
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Very nice Boyd. Good to know - great reference.
    I think that would qualify as a
    if you had a function to "talk" to googleMaps or Earth or some related product

  15. #15
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    Quote Originally Posted by orange View Post
    Very nice Boyd. Good to know - great reference.
    Thank you. Glad it was helpful.


    Quote Originally Posted by orange View Post
    I think that would qualify as a

    "if you had a function to "talk" to googleMaps or Earth or some related product"
    Interesting. Some way to detect a time zone based on information about who you want to contact. There may be a web services that can be called to lookup the time zone by ZIP or Area Code.

    This could be useful for come of my customers. I will have to check into it.

    I currently use a web service to get the atomic clock date/time GMT. I use the time zone offset to get the "local" time offset. I use it to check the PC's system clock to see it it is correct.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 11-10-2014, 03:14 AM
  2. Show current Time
    By dada in forum Programming
    Replies: 5
    Last Post: 05-03-2012, 04:32 AM
  3. Project, time, client, contact tracking
    By windwardmi in forum Database Design
    Replies: 2
    Last Post: 07-04-2011, 05:18 PM
  4. Help with Adding Time Stamp to Contact
    By shanethomp in forum Access
    Replies: 1
    Last Post: 11-09-2010, 09:43 AM
  5. Convert local time to UTC
    By zapper222 in forum Programming
    Replies: 0
    Last Post: 08-01-2010, 03:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums