Jump to content

[SOLVED] want to make proper condition for the output.


deepson2

Recommended Posts

Hello,

 

I want to differentiate my 1 day and for more than 1 day it would be 2 day(s) or 3 day(s).

 

now with this code its only getting output like 1 day(s) that i dont want. can anyone please help me. how can i get this



       $Dmin = 60 * 24;
       $Hmin = 60;


     
       $D = (int)($minutes_dif / $Dmin);
       $minutes_dif = $minutes_dif % $Dmin;

       $H = (int)($minutes_dif / $Hmin);
       $minutes_dif = $minutes_dif % $Hmin;

      
   	   else if($D > 0){
   	   echo "$D day(s) ";
   	   }
   	   else if($D == $Dmin){
	   
	   	echo "$D day ";
   	   }
   	    else if($H > 0){
	   
	   	   	   echo "$H hour(s) ";
   	   }
   	   else if($H == 1){

   	   echo "$H hour ";
   	   }


else if($minutes_dif > 0) echo "$minutes_dif minute(s) ";
else if($minutes_diff <= 0) echo "About minute ";
      echo "ago";

 

thanks in advance.

 

 

You want to just change the order round slightly for part of your IF statement:

 

            else if($H == 1){

            echo "$H hour ";
            }
             else if($H > 0){
         
                     echo "$H hours ";
            }

 

Before, $H > 0 would always be matched before $H == 1 as obviously 1 is still more than 0.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.