Solved

minus time  with PHP

Posted on 2006-07-24
4
2,120 Views
Last Modified: 2012-05-05

             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
Comment
Question by:teera
4 Comments
 
LVL 49

Assisted Solution

by:Roonaan
Roonaan earned 75 total points
ID: 17166542
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
 
LVL 40

Assisted Solution

by:RQuadling
RQuadling earned 75 total points
ID: 17166683
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
 
LVL 2

Assisted Solution

by:arun80_inin
arun80_inin earned 100 total points
ID: 17167115
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
 
LVL 32

Accepted Solution

by:
ldbkutty earned 100 total points
ID: 17174751
Looks like an Sql would also do the Job:

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now