Solved

Count time in PHP

Posted on 2001-08-21
1
1,053 Views
Last Modified: 2010-05-18
How can we count the different time  in PHP :

$time1="09/05/2001 17:59:54"
$time2="10/05/2001 18:59:54"

The result will
$time=$time2 - $time1 = "1 day 1h 0' 0'' "
0
Comment
Question by:amara_78456
1 Comment
 
LVL 4

Accepted Solution

by:
heddesheimer earned 10 total points
ID: 6411026
<?
$time1 = mktime(17, 59, 54, 5, 9, 2001);
$time2 = mktime(18, 59, 54, 5, 10, 2001);
$diff = $time2 - $time1;
echo "difference: " . $diff . " seconds<br>\n";
$days = floor($diff / (3600 * 24));
$diff -= $days * (3600 * 24);
$hours = floor($diff / 3600);
$diff -= $hours * 3600;
$minutes = floor($diff / 60);
$seconds = $diff - ($minutes * 60);

echo "diff is: $days days, $hours hours, $minutes minutes and $seconds seconds<br>\n";

?>
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

815 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

10 Experts available now in Live!

Get 1:1 Help Now