Current Date and Time based on Time Zone

  • 0
  • 1
  • Question
  • Updated 7 months ago
  • In Progress
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.
Photo of Raymond Marlon

Raymond Marlon

  • 124 Points 100 badge 2x thumb

Posted 1 year ago

  • 0
  • 1
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,436 Points 50k badge 2x thumb
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])
Photo of Raymond Marlon

Raymond Marlon

  • 124 Points 100 badge 2x thumb
Where can I create a table of users? And how should I do it?
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,436 Points 50k badge 2x thumb
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.
Photo of Carlos

Carlos

  • 654 Points 500 badge 2x thumb
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.
Photo of Michael Barrow

Michael Barrow

  • 2,206 Points 2k badge 2x thumb
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?
Photo of Carlos

Carlos

  • 654 Points 500 badge 2x thumb
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();
}
(Edited)
Photo of Michael Barrow

Michael Barrow

  • 2,206 Points 2k badge 2x thumb
Thank you! I will give this a try when I get back in the office.