Show current time merge field

  • 2
  • Question
  • Updated 5 years ago
  • Answered
Hi - we have a dynamic SKUID dashboard with a snippet refreshing the page every 5 minutes. We would like to show the current time at each refresh - something like 'Last Updated : xxxxxxx'.

I tried by adding a template at top of the page, with the following in the HTML:
Last Updated : {{$System.Now}}

but that didn't work. I have checked through the listed merge variables:

but don't see System listed. Any ideas as to how to pull in the date & time ?
Photo of Simon Parker

Simon Parker

  • 420 Points 250 badge 2x thumb

Posted 5 years ago

  • 2
Photo of Simon Parker

Simon Parker

  • 420 Points 250 badge 2x thumb
As an updated I tried creating a formula field with value = NOW, then pulling that into the model and adding that to the template. But as the template is set to 'Do not run on each row' I guess that is stopping it from working.
Photo of Simon Parker

Simon Parker

  • 420 Points 250 badge 2x thumb
Looks like I answered my own question (again..)

as I already had snippet running to do the refresh, I added code to get the date/time and insert into the appropriate element on the page:

            var currentTime = new Date();            
            var month = currentTime.getMonth() + 1;
            var day = currentTime.getDate();
            var year = currentTime.getFullYear();
            var yearstring = day + "/" + month + "/" + year;
            var hours = currentTime.getHours()
            var minutes = currentTime.getMinutes()
            if (minutes < 10){
                minutes = "0" + minutes;
            var templatetext = 'Last updated : '+hours + ':' + minutes + ' ' + yearstring;
            var elements = document.getElementById('currenttime').getElementsByTagName('*');
            elements[1].innerHTML = templatetext;
Photo of Chris


  • 1,632 Points 1k badge 2x thumb

I've had similar issues of needing to present values up to a template (or elsewhere) via mustache.  The little trick I use is to fake it as a URL parameter, such as: = new Date().toLocaleTimeString()
This puts the value into in the $Param variable, which can then be accessed in a template (or elsewhere that mustache is supported) via something like:
Last updated: {{$Param.LastTime}}
I'd love it we had a more official way to pass values up to mustache, but I've not found it yet.

Also - for formatting the date / time - here is a short hand I have used...
new Date().toLocaleTimeString() + ' on ' + skuid.$.datepicker.formatDate(skuid.utils.userLocale.dateFormat, new Date())
which outputs something like
7:46:44 AM on 3/26/2015
So the final (hack) string to do it all is... = new Date().toLocaleTimeString() + ' on ' + skuid.$.datepicker.formatDate(skuid.utils.userLocale.dateFormat, new Date());

- Chris
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 45,308 Points 20k badge 2x thumb
We like a good hack every once in a while.  Yours is a good one. 
Photo of Jack Sanford

Jack Sanford, Champion

  • 10,612 Points 10k badge 2x thumb
I like this a lot, I just need the reverse - .toLocaleDateString works great for my date, but the .toLocaleTimeString adds seconds to the time, which makes it not work for my date/time field I'm trying to send data to through my URL

I'm trying to use .formatTime ("h:mm a", new Date()) but it just crashes no matter what I try

e.g. = new Date().formatTime ("h:mm a", skuid.time.getSFDateTime) or = skuid.time.getSFDateTime().formatTime ("h:mm a", new Date()) 

i just don't know how to add the formatTime function...