Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Count time in PHP

Posted on 2001-08-21
1
Medium Priority
?
1,094 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 4

Accepted Solution

by:
heddesheimer earned 40 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

Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
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 …
Suggested Courses

730 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