Senin, 31 Maret 2008

. Senin, 31 Maret 2008

waktu mengerjakan suatu project php, ternyata di butuhkan perhiungan untuk menentukan apakah sebuah invoice telah di bayar atau belum kemudian apakah jangka waktu nya sudah habis ato belum, nach akhirrnya aku berkunjung ke mbah google.com dan mendapatkan fungsi ini dari http://www.esn.or.id/ yang asalnya dari sonny-ak.com , gunanya untuk menghitung jumlah hari

function dateDiff($interval,$dateTimeBegin,$dateTimeEnd) {
//Parse about any English textual datetime
//$dateTimeBegin, $dateTimeEnd

$dateTimeBegin=strtotime($dateTimeBegin);
if($dateTimeBegin === -1) {
return("..begin date Invalid");
}

$dateTimeEnd=strtotime($dateTimeEnd);
if($dateTimeEnd === -1) {
return("..end date Invalid");
}

$dif=$dateTimeEnd - $dateTimeBegin;

switch($interval) {
case "s"://seconds
return($dif);

case "n"://minutes
return(floor($dif/60)); //60s=1m

case "h"://hours
return(floor($dif/3600)); //3600s=1h

case "d"://days
return(floor($dif/86400)); //86400s=1d

case "ww"://Week
return(floor($dif/604800)); //604800s=1week=1semana

case "m": //similar result “m” dateDiff Microsoft
$monthBegin=(date("Y",$dateTimeBegin)*12)+
date("n",$dateTimeBegin);
$monthEnd=(date("Y",$dateTimeEnd)*12)+
date("n",$dateTimeEnd);
$monthDiff=$monthEnd-$monthBegin;
return($monthDiff);

case "yyyy": //similar result “yyyy” dateDiff Microsoft
return(date("Y",$dateTimeEnd) - date("Y",$dateTimeBegin));

default:
return(floor($dif/86400)); //86400s=1d
}
}
?>
nah cara nampilkannya begini
< ? echo dateDiff(”d”,”2005/02/12″,”2006/02/14″); ?>

mudah-mudahan berguna ?

0 komentar:

 
specials thanks to : Blogger.com | Template by miscah.blogspot.com