Reputation: 97
I am new to developing. So I am confused making of total elapsed time using php and JavaScript. I tried searching for this answer. What ever I get is for countdown measurement. I need to calculate the time from starting to end using php.I got an partial answer in fiddle. But I am not aware of how to stop this timer. I want to calculate the work of employee where he/she explicitly chooses the status. When user select Working, the timer should start. As soon as the user select complete the timer should stop.The result should be inserted into MySQL database to see how many hours he/she have spent for working. This is the logic I am looking for. Really I am helpless to implement it. I am developing this on my own to develop myself and I don't have any guide to guide me. I know this type of question are not accepted in this forum but I badly need of help
Upvotes: 0
Views: 98
Reputation: 99
What about storing the data in a table with the structure:
id, worker, start_timestamp, end_timestamp
Then, simply start a session by inserting the worker detail and start timestamp. After the user has ended the session, compare the times using the following code:
// convert to unix timestamps
$firstTime=strtotime($firstTime);
$lastTime=strtotime($lastTime);
// perform subtraction to get the difference (in seconds) between times
$timeDiff=$lastTime-$firstTime;
Upvotes: 1
Reputation: 378
You could use setInterval and clearInterval:
var intervalId;
function count() {
...
}
$('#start-button').click(function() {
if ( !intervalId ) {
intervalId = setInterval( count, 1000 );
}
});
$('#stop-button').click( function() {
if ( intervalId ) {
clearInterval( intervalId );
}
});
Upvotes: 0