16 Ekim 2014, 15:06
|
#1 |
Çevrimdışı
Kullanıcıların profil bilgileri misafirlere kapatılmıştır.
| iki tarih arasındaki farkı yıl ay gün saat olarak ayırarak bulmak
PHP Kod: Kodu kopyalamak için üzerine çift tıklayın!
<?php
function timeDiff($t1, $t2)
{
if($t1 > $t2)
{
$time1 = $t2;
$time2 = $t1;
}
else
{
$time1 = $t1;
$time2 = $t2;
}
$diff = array(
'years' => 0,
'months' => 0,
'weeks' => 0,
'days' => 0,
'hours' => 0,
'minutes' => 0,
'seconds' =>0
);
foreach(array('years','months','weeks','days','hours','minutes','seconds')
as $unit)
{
while(TRUE)
{
$next = strtotime("+1 $unit", $time1);
if($next < $time2)
{
$time1 = $next;
$diff[$unit]++;
}
else
{
break;
}
}
}
return($diff);
}
$start = strtotime('2007-01-15 07:35:55');
$end = strtotime('2009-11-09 13:01:00');
$diff = timeDiff($start, $end);
$output = "The difference is:";
foreach($diff as $unit => $value)
{
echo " $value $unit,";
}
$output = trim($output, ',');
echo $output;
?>
__________________ |
| |