Kaan - 2012-10-15 21:52 GMT -
?ki tarih aral???ndaki zaman de?erini hesaplamak i?in basit bir fonksiyon geli?tiriyoruz.
Bu fonksiyon ile iki tarih aras?ndaki g?nleri liste halinde alabiliriz ve tablo d?k?m i?lemlerinde rahat?a kullanabiliriz.
Fonksiyonumuza ge?elim;
?rnek Kullan?m;
?ki tarih aral???ndaki zaman de?erini hesaplamak i?in basit bir fonksiyon geli?tiriyoruz.
Bu fonksiyon ile iki tarih aras?ndaki g?nleri liste halinde alabiliriz ve tablo d?k?m i?lemlerinde rahat?a kullanabiliriz.
Fonksiyonumuza ge?elim;
:
hp]function DaysBetweenDates($strDateFrom,$strDateTo)
{
$aryRange=array();
$iDateFrom=mktime(1,0,0,substr($strDateFrom,5,2), substr($strDateFrom,8,2),substr($strDateFrom,0,4));
$iDateTo=mktime(1,0,0,substr($strDateTo,5,2), substr($strDateTo,8,2),substr($strDateTo,0,4));
if ($iDateTo>=$iDateFrom)
{
array_push($aryRange,date('Y-m-d',$iDateFrom)); // first entry
while ($iDateFrom<$iDateTo)
{
$iDateFrom+=86400; // add 24 hours
array_push($aryRange,date('Y-m-d',$iDateFrom));
}
}
return $aryRange;
}
{
$aryRange=array();
$iDateFrom=mktime(1,0,0,substr($strDateFrom,5,2), substr($strDateFrom,8,2),substr($strDateFrom,0,4));
$iDateTo=mktime(1,0,0,substr($strDateTo,5,2), substr($strDateTo,8,2),substr($strDateTo,0,4));
if ($iDateTo>=$iDateFrom)
{
array_push($aryRange,date('Y-m-d',$iDateFrom)); // first entry
while ($iDateFrom<$iDateTo)
{
$iDateFrom+=86400; // add 24 hours
array_push($aryRange,date('Y-m-d',$iDateFrom));
}
}
return $aryRange;
}
?rnek Kullan?m;
Kod:
$gunler=DaysBetweenDates(?2012-01-15″,?2012-02-05″);