Skip to main content
Question

How can I use javascript to get current date/time to use as a variable in a formula

  • February 26, 2018
  • 0 replies
  • 89 views

I have tried to find a way to put a javascript in as a variable to get the current date and time. It would have been great to use the native 'Now()' function but it only uses the time that the page last refreshed. The below code is what I hope to use once I can insert as a variable.
function timeNow(i) {    var d = new Date(),        h = (d.getHours()<10?'0':'') + d.getHours(),        m = (d.getMinutes()<10?'0':'') + d.getMinutes();    i.value = h + ':' + m;&nbsp;
}
And honestly I am such a low coder that this will probably not work. The rest of my formula that I am planning to use works perfectly except for getting a current time variable that is accurate. Has anyone done this before or knows how to do this in a simple manner that even a low coder can manage it?
This topic has been closed for replies.

  • Registered
  • February 26, 2018
The formula language does not have access to JavaScript. Formulas evaluate server-side to Now() evaluates to the time a page is  initially loaded as you have noted. Script evaluates client-side so it has access to every event the user initiates as well as the time of those events.

You did not mention what you wanted to achieve overall but I would guess the four use cases in this new demo might come very close to what you want:

New Demo: Time On Form
https://community.quickbase.com/quickbase/topics/new-demo-time-on-form

If you need assistance in implementing one of the use cases in this demo (or some other use case) feel free to contact me off-world using the information in my profile:

https://getsatisfaction.com/people/dandiebolt/