Calculating how long it took the user to complete the task

I am trying to create basic task where user can get time of much time it took him to get the single task done In database I set start_date to date(), and when user submit post($_POST['submit] it should echo how for how much time he finish it. Basically it would do something like: $difference = $start_date - $end_date; echo $difference; // shows time. But I don’t want to set end_date into database, just want to display it on the screen. I appreciate any help

You sure about that? Consider your use cases.

In the meantime, Date_Diff

You could do this within the database

select '2019-09-11'::date - now()
-- 0 years 0 mons -5 days -6 hours -41 mins -11.238336 secs

Or you use any data/time column for the variable.


It’s a tactical decision whether you choose to store the end_date or not.

BUT IF, this info is not to be stored for tater use. It would relegate it to USER_DISPLAY. AND if it’s meant simply for USER DISPLAY, why not handle it client side with .js?

Another method would depend on page reload ( I assume the form is being processes and there is some sort of confirmation routine) You could have the page generate timestamp, and pass it along to the process script, which also generates a timestamp, and thus you can figure the difference from there.

This method however is that someone could load the page and NOT START working on the task for some period of time… where as with javascript you could set the momentum one of the form field gains focus… regardless of how much idle time occurred prior to that.

Hope that helps.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.