PHP Tarih Foksiyonlari: gecen süreyi yazdirmak

Use of function:


[code]<?php

$s = mktime(9, 30, 0, 07, 15, 1990);

list($year,$month,$day,$hour,$minute,$second) = split('[:-]' ,date('Y-m-d H:i:s'));
$e = mktime($hour, $minute, $second, $month, $day, $year);

echo Duration($s, $e);

?>[/code]
Output:

16 years 40 weeks 6 days 7 hours 44 minutes

Function :

[code]
<?php

function Duration($s, $e){

/* Find out the seconds between each dates */
$timestamp = $e - $s;

/* Cleaver Maths! */
$years=floor($timestamp/(60*60*24*365));$timestamp%=60*60*24*365;
$weeks=floor($timestamp/(60*60*24*7));$timestamp%=60*60*24*7;
$days=floor($timestamp/(60*60*24));$timestamp%=60*60*24;
$hrs=floor($timestamp/(60*60));$timestamp%=60*60;
$mins=floor($timestamp/60);$secs=$timestamp%60;

/* Display for date, can be modified more to take the S off */
if ($years >= 1) { $str.= $years.' years '; }
if ($weeks >= 1) { $str.= $weeks.' weeks '; }
if ($days >= 1) { $str.=$days.' days '; }
if ($hrs >= 1) { $str.=$hrs.' hours '; }
if ($mins >= 1) { $str.=$mins.' minutes '; }

return $str;

}

?>[/code]

Konular

Hanci.org sizlere daha iyi hizmet sunmak için çerezleri kullanıyor.
Hanci.org sitesini kullanarak çerez politikamızı kabul etmiş olacaksınız.
Detaylı bilgi almak için Gizlilik ve Çerez Politikası metnimizi inceleyebilirsiniz.