CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> Archive -> GotoCode Archive

 PHP date difference (timestamps)

Print topic Send  topic

Author Message
Steve F.
Posted: 04/10/2002, 9:34 AM

Looking for any examples of how to display the difference between to timestamps ( "mktime()" ) in Days, Hours, Seconds. I have been trying a few examples from different places, and can't seemn to find one that works.

I have:
$fldsubmitdate which is in timestamp format
$fldtimeinqueue which is "supposed" to be how long the submission has been in queue.

Any help would be greatly appreciated.

Thanks,
Steve
Si Cranmer
Posted: 04/10/2002, 1:11 PM

Steve,

This should do you, need anu others mail me on {initial}{surname}@consultant.com

Si.

function DateDiff($begin,$end)
{
//for two timestamp format dates, returns the plain english difference between them.
//note these dates are UNIX timestamps


$diff=$end-$begin;

$years=intval($diff/(60*60*24*365));
$diff=$diff-($years*(60*60*24*365));

$months=intval($diff/(60*60*24*30));
$diff=$diff-($months*(60*60*24*30));

$weeks=intval($diff/(60*60*24*7));
$diff=$diff-($weeks*(60*60*24*7));

$days=intval($diff/(60*60*24));
$diff=$diff-($days*(60*60*24));

$hours=intval($diff/(60*60));
$diff=$diff-($hours*(60*60));

$minutes=intval($diff/(60));
$seconds=$diff-($minutes*60);

$s="";

if ($years<>0) $s.= $years." years ";
if ($months<>0) $s.= $months." months ";
if ($weeks<>0) $s.= $weeks." weeks ";
if ($days<>0) $s.= $days." days ";
if ($hours<>0) $s.= $hours." hours ";
if ($minutes<>0) $s.= $minutes." minutes ";
if ($seconds<>0) $s.= $seconds." seconds ";

return $s;

}

   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.