Solved

Count time in PHP

Posted on 2001-08-21
1
1,042 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

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

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

911 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

19 Experts available now in Live!

Get 1:1 Help Now