This topic is locked

Time difference between end time and start time

7/26/2021 10:56:44 PM
PHPRunner General questions
J
Jan Desaer author

Dears,

I have 3 time fields defined in MySQL DB:

  • StartTime
  • EndTime
  • WorkingHours

I want the field "WorkingHours" being updated with time difference between EndTime and StartTime.

Values of fields:
StartTime : "08:00"
EndTime: "17:00"
WorkingHours should be filled up with value "09:00". Is there a possibility to do this?

I've tried TIMEDIFF(EndTime,StartTime) but this is resulting in "Fatal error: Uncaught Error: Call to undefined function TIMEDIFF() in /home/buttonhandler.php:90 Stack trace: #0 /home/buttonhandler.php(54): fieldEventHandler_Pauze_event(Array) #1 {main} thrown in /home/buttonhandler.php on line 90"

Thank you for the support.

HJB 7/27/2021

Date / Time Handling in web applications

... for inspiration ..., above URL content owns TWO examples in regard to
calculate HOURS from two time fields, one for MySQL and as PHP code.

M
Mark Kramer 8/1/2021

For insperation. Set variables acording to your needs. The code goes in the Javascript OnLoad event for the corresponding page.

var ctrlDate = Runner.getControl(pageid,'TimeOut');
var CD = Runner.getControl(pageid,'TimeIn');

var DO = new Date(CD.getValue());
var DOP = Date.parse(DO) ;

var CT = new Date(ctrlDate.getValue());
var dp = Date.parse(CT) ;

var TT = Runner.getControl(pageid,'Totaltime');
var cl = Runner.getControl(pageid,'closed');

// get total seconds between the times
var delta = Math.abs(dp - DOP) / 1000;

// calculate (and subtract) whole days
var days = Math.floor(delta / 86400);
delta -= days * 86400;

// calculate (and subtract) whole hours
var hours = Math.floor(delta / 3600) % 24;
delta -= hours * 3600;

// calculate (and subtract) whole minutes
var minutes = Math.floor(delta / 60) % 60;
delta -= minutes * 60;

// what's left is seconds
var seconds = delta % 60;

//tto =(days)+" day(s) "+(hours)+" hr(s) "+(minutes)+" min "+(seconds)+" sec "

function func(){
var CT = new Date(ctrlDate.getValue());
var dp = Date.parse(CT) ;

tto =(hours)+" hr(s) "+(minutes)+" min "
TT.setValue(tto);
cl.setValue(1);
};

CD.on('keyup', func);
ctrlDate.on('keyup', func);