Manage Learn to apply best practices and optimize your operations.

Showing elapsed time in web views without using Today

This tip describes the procedure for showing elapsed time in web views without using Today.

If you use @today or @now function in view columns or selection formulas, it will result in noticable performance problem on server.

In Web environment, we have a powerful tool: javascript...

We will have a view with a field StartDateTime and we are going to show the time between now and StartDateTime.

Code is self-explanatory...

function showElapsed() {

// **************************************************************
//  Display elapsed time at the web client
//  (C) Serdar Basegmez
//   (anti-spam precaution :)))
// **************************************************************
// 1-->
// dateadjustment is a variable that needs to be computed at the top of form. It shows us the difference of server's now and browser's now. We
// avoid negative elapsed times with the variable. At the top of template of the view ($$View Template of XXX), place a computed-for-display 
// field with the following formula. This notation is used to avoid date format conflicts...
//    yr:=@Text(@Year(@Now));
//    mnt:=@Text(@Month(@Now)-1);
//    dy:=@Text(@Day(@Now));
//    hr:=@Text(@Hour(@Now));
//    mn:=@Text(@Minute(@Now));
//    sc:=@Text(@Second(@Now));
//    "[<SCRIPT>var dayAtServer=new Date("+yr+"," +mnt+ "," +dy+ "," + hr+ "," +mn + "," +sc+ "); 
//     var dateadjustment=((new Date())-dayAtServer)"+"</SCRIPT>]"

// 2 -->
// You should place a declaration in JS Header of template of the view:
// var dates=new Array();

// 3-->
// You should place a column in a view that has a formula: It creates div's with unique names. The code set inner html's of div's according to related
// member of dates array. You should beware of replication conflicts and response documents... I have excluding these documents in the view.
// ourdate:=StartDateTime;
// yr:=@Text(@Year(ourdate));
// mnt:=@Text(@Month(ourdate)-1);
// dy:=@Text(@Day(ourdate));
// hr:=@Text(@Hour(ourdate));
// mn:=@Text(@Minute(ourdate));
// sc:=@Text(@Second(ourdate));
// order:=@Text(@DocNumber(""));
// "[<div ID='ElapsedTime"+order+"'></DIV><SCRIPT>dates["+order+"]=new Date("+yr+"," +mnt+ "," +dy+ "," + hr+ "," +mn + "," +sc+ ");</SCRIPT>]"

var datenow=(new Date())-dateadjustment;  // computes date of the server.
var i=1;

while (dates[i]!=null)  // Loop until the last doc...
var elapsed=0;
elapsed=Math.floor((datenow-dates[i])/60000);  //compute elapsed time in minutes. This can be replaced... division by 1000 gives time in seconds.

if (elapsed>=1440) {
 showdt+=String(Math.floor(elapsed/1440))+"d:";   //compute # of days...
if (elapsed>=60) {
 showdt+=String(Math.floor(elapsed/60))+"h:";   // compute # of hours
if (elapsed!=0) {
 showdt+=String(Math.floor(elapsed))+"m";   //compute # of minutes

document.getElementById("ElapsedTime"+i).innerHTML = "<Center>"+showdt+"</Center>"; //place the element...

counter=setTimeout("showElapsed()",1000);  //I am using this command to refresh the elapsed times each second. I am not using it for large views.


showElapsed();   //initiate the function...

Dig Deeper on Domino Resources - Part 4

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.




  • iSeries tutorials's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...