hi guys..
I have made a function which counts the numbers of days or hours or minutes from the current datetime to the give datetime.. but i am confused while displaying number of days along with number of hours.. rest all works fine(I Suppose).
here is the code :
[CODE=PHP]
function day_counter($da te,$msg){
$today=time();
$day_to_count=s trtotime($date) ;
if($day_to_coun t>$today){
$rem=$day_to_co unt-$today;
}
else {if($today>$day _to_count){
$rem=$today-$day_to_count;
}}
if($rem>=86400) {
$days=$rem/86400;
$days=round($da ys,2);
$dys=(int)$days ;
$h=(float)strst r($days,".");
$h=round($h*24) ;
if($h==24)
$dys+=1;
if($h<=0 OR $h==24)
return "<b>".$dys. "</b> Days ".$msg;
return "<b>".$dys. "</b> Days <b>".$h."</b> Hours ".$msg;
}
if($rem>=3600){
$hours=$rem/3600;
$hours=round($h ours,2);
$hrs=(int)$hour s;
$mn=(float)strs tr($hours,".");
$mn=ceil($mn*60 );
if($mn<=0)
return "<b>".$hrs. "</b> Hours ".$msg;
return "<b>".$hrs. "</b> Hours <b>".$mn."</b> Minutes ";
}
if($rem>=60){
$min=$rem/60;
$min=round($min ,2);
$mnm=(int)$min;
$sec=(float)str str($min,".");
$sec=ceil($sec* 60);
if($sec<=0)
return "<b>".$mnm. "</b> Minutes ".$msg;
return "<b>".$mnm. "</b> Minutes <b>".$sec." </b>Seconds";
}
if($rem>0 && $rem<60){
return "<b>".$rem. "</b> Seconds".$msg;
}
}[/CODE]
And i want to know, is this the right way to get the decimal part of a number ?
I have made a function which counts the numbers of days or hours or minutes from the current datetime to the give datetime.. but i am confused while displaying number of days along with number of hours.. rest all works fine(I Suppose).
here is the code :
[CODE=PHP]
function day_counter($da te,$msg){
$today=time();
$day_to_count=s trtotime($date) ;
if($day_to_coun t>$today){
$rem=$day_to_co unt-$today;
}
else {if($today>$day _to_count){
$rem=$today-$day_to_count;
}}
if($rem>=86400) {
$days=$rem/86400;
$days=round($da ys,2);
$dys=(int)$days ;
$h=(float)strst r($days,".");
$h=round($h*24) ;
if($h==24)
$dys+=1;
if($h<=0 OR $h==24)
return "<b>".$dys. "</b> Days ".$msg;
return "<b>".$dys. "</b> Days <b>".$h."</b> Hours ".$msg;
}
if($rem>=3600){
$hours=$rem/3600;
$hours=round($h ours,2);
$hrs=(int)$hour s;
$mn=(float)strs tr($hours,".");
$mn=ceil($mn*60 );
if($mn<=0)
return "<b>".$hrs. "</b> Hours ".$msg;
return "<b>".$hrs. "</b> Hours <b>".$mn."</b> Minutes ";
}
if($rem>=60){
$min=$rem/60;
$min=round($min ,2);
$mnm=(int)$min;
$sec=(float)str str($min,".");
$sec=ceil($sec* 60);
if($sec<=0)
return "<b>".$mnm. "</b> Minutes ".$msg;
return "<b>".$mnm. "</b> Minutes <b>".$sec." </b>Seconds";
}
if($rem>0 && $rem<60){
return "<b>".$rem. "</b> Seconds".$msg;
}
}[/CODE]
And i want to know, is this the right way to get the decimal part of a number ?
Comment