• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2130
  • Last Modified:

minus time with PHP


             robert      2006-07-10 15:12:39       NULL       2006-07-10 08:00:00       NULL
             Jhon      2006-07-10 15:12:53       NULL       2006-07-10 08:00:00       NULL
             david     2006-07-11 13:48:38       NULL       2006-07-11 08:00:00       NULL

how can i minus time   such as below

 2006-07-10 15:12:39       -       2006-07-10 08:00:00

 2006-07-10 15:12:53       -      2006-07-10 08:00:00
0
teera
Asked:
teera
4 Solutions
 
RoonaanCommented:
You make timestamps out of them using strtotime. Then you do $secondsDiff = $time2 - $time1

Then you need to format it in the way you like.

-r-
0
 
Richard QuadlingSenior Software DeverloperCommented:
Watch out for certain limits on different OSs. Some don't like -ve time. So make sure you always use ...

$secondsDiff = abs($time2 - $time1);

0
 
arun80_ininCommented:
You can use mktime like this

diff=mktime(hr1,min1,sec1,mon1,day1,year1)-mktime(hr2,min2,sec2,mon2,day2,year2);

to convert this diference to date you can do like this date("Y-m-d H:i:s",diff);
0
 
ldbkuttyCommented:
Looks like an Sql would also do the Job:

SELECT TIMEDIFF(col1, col2) AS time_diff FROM table_name
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now