Special Date Calculation ...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pepe_lepew1962
Forum Commoner
Posts: 44
Joined: Thu Nov 20, 2008 10:29 am

Special Date Calculation ...

Post by pepe_lepew1962 »

Hello, I REALLY need some help creating a special date calculation. I want to calculate the difference between
2 mysql fields but display the difference as:
//
//
02:19:21
//
02 is days
19 is hours
21 as minutes
//
//
$Dater01 = $row['tblTabler00_Dater01']; //2010-12-16 23:45:00
$Dater02 = $row['tblTabler00_Dater02']; //2010-12-14 04:24:00
//
$Dater03 = $Dater01 - $Dater02
//
Important is that a negative amount is valid, meaning it is overdue. Any help would be greatly appreciated.
//
Regards,
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: Special Date Calculation ...

Post by s.dot »

In PHP >= 5.3 you can use the built in datetime class
http://www.php.net/manual/en/datetime.diff.php

Here is an example from the manual:

Code: Select all

<?php
$datetime1 = new DateTime('2009-10-11');
$datetime2 = new DateTime('2009-10-13');
$interval = $datetime1->diff($datetime2);
echo $interval->format('%R%a days');
?>
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply