-1

I am trying to make a clocking system so that people I make websites for can see what I have done when. I have two time stamps in a SQL database.

I want to find out how many hours are between them as I am paid by the hour. When I query my table, i get the time stamps and assing them to variables

$clock_in;
$clock_out;

And i want to find the hours/mins between them. Thanks

Sherlock
  • 7,525
  • 6
  • 38
  • 79
nmyster
  • 454
  • 1
  • 7
  • 20
  • 1
    Possible dublicate: http://stackoverflow.com/questions/365191/how-to-get-time-difference-in-minutes-in-php – Peon Jul 10 '12 at 12:00
  • 3
    What are those timestamps? UNIX timestamps? Which are **seconds since 1970**? Which you can **subtract** from each other, then **divide** by the number of seconds per minute and minutes per hour... \*cough\*cough\* – deceze Jul 10 '12 at 12:01

2 Answers2

1

Use the PHP strtotime() function on your SQL timestamp, then simply subtract $clock_in from $clock_out to give you the number of seconds between the two. Divide by 60 to get minutes.

$minutes = ($clock_out - $clock_in) / 60
Dan
  • 526
  • 9
  • 28
1
select time_to_sec(timediff('2010-09-01 03:00:00', '2010-09-01 00:10:00' )) / 3600;

+-----------------------------------------------------------------------------+
| time_to_sec(timediff('2010-09-01 03:00:00', '2010-09-01 00:10:00' )) / 3600 |
+-----------------------------------------------------------------------------+
|                                                                      2.8333 | 
+-----------------------------------------------------------------------------+

Also read this for difference in seconds.

Community
  • 1
  • 1
Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276