Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.