Solved

Count time in PHP

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

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JQuery Search Filter 2 69
MSSQL - Lock Row from reading by other programs 9 57
restriction of entering a a page 5 31
Dump data from mysql to xls php 10 20
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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 look for a specific file type in a local or remote server directory using PHP.

756 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