Discussions

Expand all | Collapse all

Current Date and Time based on Time Zone

  • 1.  Current Date and Time based on Time Zone

    Posted 07-31-2017 16:50
    How can I create Date / Time field that would show current Date / Time based on my Time Zone? I already used Now() but still the current field I have is showing U.S. Eastern Time. How can I make it based on my own Time zone. Please advise.


  • 2.  RE: Current Date and Time based on Time Zone

    Posted 07-31-2017 17:04
    I assume that you know that you can set the app to a particular Time Zone for all users, but you are saying that you are in a different time zone from most of the rest of the users.

    You would need to have a table of users with a key field of userid and their time zone offset from the time zone that the app is set for.  Then a relationship to any other tables in the app where you want to show local time and have a calculated field which calculates the Now() value or any other date/.time field such as [Date created] and add hours according to the offset.  

    The right side of the relationship will need to be a formula user field typically called [Current User] with a formula of User()

     for example

    [Date Created] + Hours([offset hours])


  • 3.  RE: Current Date and Time based on Time Zone

    Posted 08-01-2017 15:22
    Where can I create a table of users? And how should I do it?


  • 4.  RE: Current Date and Time based on Time Zone

    Posted 08-01-2017 15:26
    You would create a New Table called perhaps User Time Zones with a Key field of userid and a field for the hours offset as a numeric field.


  • 5.  RE: Current Date and Time based on Time Zone

    Posted 04-23-2018 15:24
    Is there a way to get the current date/time (on a button and then to a field) when the user hasn't refreshed the page in a couple of hours? (Attempting to track time dedicated to work, so they open a record when they start to work on a given task, but they consistently fail to refresh before closing it (using a button) so it stores the date/time of the last page refresh, instead of the current time.


  • 6.  RE: Current Date and Time based on Time Zone

    Bronze
    Contributor
    Posted 04-23-2018 15:29
    Yeah, very frustrating! I would love an answer to this, as it makes my time sheet app much more difficult to use for my end users. Is there some clever javascript that can be added to a button to overcome this?


  • 7.  RE: Current Date and Time based on Time Zone

    Posted 04-23-2018 16:32
    Michael, I think i just got it.! (there are references to someone else's code here... cannot remember who or where. If anyone feels they should be credited, please say so!)

    Formula URL Button:
    "javascript:" &
    "var QBU_key = '" & [Record ID#] & "';" &
    "$.getScript(gReqAppDBID + '?a=dbpage&pagename=STOPACTIVITY.js');" &
    "void(0);"

    Then the JS File (STOPACTIVITY.js):

    var apptoken = "type_the_apptoken_here";
    $.ajaxSetup({data: {apptoken: apptoken}});
    //this one prompts the user for an input describing what he'd been doing...
     var motive = prompt("In this activity I was doing: ");
    //this is the basic setup for the date. TimeZone for US timeZones and format you may change es-CR to en-US and the timeZone to America/New_York, etc. hour12:true will display in 12 hour format. False will display as 24h.
    var event = new Date(Date.now());
    date = event.toLocaleString('es-CR', { timeZone: 'America/Costa_Rica', hour12:true} );
    if(motive == null){
        alert("No task description was input. No changes were performed.");
    record
    }else {
    var promise = $.get(gReqDBID,{
      act: "API_EditRecord",
      rid: QBU_key,
      _fid_12: motive,
     _fid
      _fid_57: date
    });
    alert("Activity Ended.");
    location.reload();
    }


  • 8.  RE: Current Date and Time based on Time Zone

    Bronze
    Contributor
    Posted 04-23-2018 17:51
    Thank you! I will give this a try when I get back in the office._