Calculating the difference between two time variables

  • Published by Viedoc System 2018-11-13
  • Print

This example shows how to calculate the difference in time between two time variables.

To calculate the difference in time between the variables Start time and Stop time as illustrated in the image, enter the below code:

if (!START || !END) return null;

var diff = (END - START) / (1000 * 60); // minutes

return diff;

or

if (!START || !END) return null;

var diffInMinutes = ( END.getHours()*60+END.getMinutes() ) - ( START.getHours()*60+START.getMinutes() )

return diffInMinutes;

For more details about functions and how to use JavaScript in Viedoc see lesson Using JavaScript in Viedoc.

Note! As it is not possible to have time without a date in JavaScript the date is set automatically to current site date when the time is selected.