Quick Base Discussions

Expand all | Collapse all

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

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

    Posted 02-25-2018 19:55
    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?


  • 2.  RE: How can I use javascript to get current date/time to use as a variable in a formula

    Top
    Contributor
    Posted 02-26-2018 10:04
    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/


  • 3.  RE: How can I use javascript to get current date/time to use as a variable in a formula

    Top
    Contributor
    Posted 02-26-2018 10:21
    >And honestly I am such a low coder that this will probably not work.

    BTW, don't be so self-deprecating - you can do the code stuff.
    Low Code platforms  like QuickBase are a great way to learn code.


  • 4.  RE: How can I use javascript to get current date/time to use as a variable in a formula

    Posted 02-26-2018 13:07
    The use case -
    We run IT projects (some overnight) in 8 different time zones and our staff or the technicians will have to check-in and out for each site. I have a check in/out button that populates the times but all in eastern time (our main office time and the app is set to eastern). I have the ability to translate time to any time zone and take into account daylight savings time. The organization is wanting to move toward capturing all those times in local time on the project site which I can make happen but only in a separate field but not immediately with the button.
     It is just that pesky now() function standing in my way at this point. I like the concept of the demos and could find a few use cases. In this case I need the real time/date the button is clicked on.

    Thanks for the words of encouragement, I am not that self-deprecating it is frustrating being on the verge of understanding and knowing you are there but not sure if how long it will take to get there.