Jump to content

time difference on details datapage


Recommended Posts

Hi Mylene,

Add header/footer to your datapage and in the footer try using the following script:

<SCRIPT LANGUAGE="JavaScript">
window.addEventListener("load", myfunction1);
document.getElementById("caspioform").addEventListener("submit", myfunction);

document.getElementById("caspioform").addEventListener("submit", getDiff);

function myfunction1() {

Stamp = new Date();
 var v_TimeStamp;
 Hours = Stamp.getHours()
 Mins = Stamp.getMinutes();
 if (Mins < 10) {
   Mins = "0" + Mins;
 }
 
 v_TimeStamp=('' + (Stamp.getMonth() + 1) +"/"+Stamp.getDate()+ "/"+Stamp.getFullYear() + ' ' + Hours + ":" + Mins);
document.getElementById("EditRecordStart_Date").value=v_TimeStamp;

}
function myfunction() {

 Stamp = new Date();
 var v_TimeStamp;
 Hours = Stamp.getHours()
 Mins = Stamp.getMinutes();
 if (Mins < 10) {
   Mins = "0" + Mins;
 }
   v_TimeStamp=('' + (Stamp.getMonth() + 1) +"/"+Stamp.getDate()+ "/"+Stamp.getFullYear() + ' ' + Hours + ":" + Mins);
document.getElementById("EditRecordEnd_Date").value=v_TimeStamp;

}

function getDiff()
 { 
   var v_sDate = document.getElementById("EditRecordStart_Date").value;
   var v_eDate = document.getElementById("EditRecordEnd_Date").value;
   var sDate = new Date(v_sDate);
   var eDate = new Date(v_eDate);


var timeDiff = Math.abs(eDate.getTime() - sDate.getTime());
var diffDays = Math.ceil(timeDiff / (1000 * 3600)); 
   document.getElementById("EditRecordDifference").value=diffDays;
 }   

</SCRIPT>


Replace "Start_Date" with your field name of the field for date, when user opens the record

Replace "End_Date" with your field name of the field for date, when user updates the record

Replace "Difference" with your field name of the field for time difference 

Link to post
Share on other sites
  • 2 years later...
  • 6 months later...

Hello  @Mylene,

 

In addition to @WatashiwaJin's answer, you would need to have two Date/Time fields and one optional formula field on your table to calculate the time they spend populating it (i.e. from when the page was loaded, to when the form was submitted).

 

For the time_start field, you may do an (Advanced) > OnLoad > Timestamp

image.png.ed2fe1668b3e5de5c1d20c2e5e8a42fb.png

 

For the time_end field, DO make sure that the timestamp is selected on the Form Element: setting.

image.png.f961b364a66eb4d953b40b0a35bc1f62.png

 

As for calculating the time in between, you may define a Formula Formula field in your table that has the syntax of:

DATEDIFF(
  hour,
  [@field:time_start],
  [@field:time_end]
)

More information about formula fields: https://howto.caspio.com/tables-and-views/data-types/formula-fields/

Function Reference: https://howto.caspio.com/function-reference/

 

Hope this helps.

 

-DN31337!

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...