-1

I have a table in the database with the name attendance. It has three columns: intime, outtime and work_hours. I have date and time in intime and outime. Now I want to write the php code to calculate the time difference in the format hh:mm:ss to store into the column work_hour of attendance table.

Please help me out.

smottt
  • 3,272
  • 11
  • 37
  • 44
Rajeet
  • 37
  • 1
  • 8

2 Answers2

0

timediff returns the difference between two datetimes as a time value:

UPDATE attendance
SET    work_hours = TIMEDIFF (outtime, intime)
Mureinik
  • 297,002
  • 52
  • 306
  • 350
0

I have one simple solution, but you will find better. Just try this. For this you need to convert both of your outtime and intime in seconds using

$working_time_in_seconds = strtotime($outtime) - strtotime($intime);

echo date('H:i:s', $working_time_in_seconds );
Codelord
  • 1,120
  • 2
  • 10
  • 21