Jump to content

days on countdown


shocker-z

Recommended Posts

Hi shocker

Try this
[code]
<?PHP
function NoOfDays($Num){

  $years = 0;
  $months = 0;
  $weeks = 0;
  $days = 0;

  $test = floor($Num/365.25);
  if($test > 0){
  $years = $test;
  $difference = $Num - ($years*365.25);
  }

  $test = floor($difference/30.4);
  if($test > 0){
  $months = $test;
  $difference = $difference - ($months*30.4);
  }

  $test = floor($difference/7);
  if($test > 0){
  $weeks = $test;
  $difference = $difference - ($weeks*7);

  }
  if ($difference >= 1){
  $days = $difference;
  }

  $output = "You have to wait $years Years, $months Months, $weeks Weeks, $days Days until this Day";

  return $output;
}

echo NoOfDays(424);

?>[/code]
it works on the principle that each year has 365.25 days (to take into account the extra day every 4 years), every month has 30.4 days in it (to take into account that for 365.25 days divided by 12 months = 30.4), each week has seven days ( all weeks have seven days I know but...) and so on..

the above code entered with you posted number of 424 returns

[code] You have to wait 1 Years, 1 Months, 4 Weeks, 0 Days until this Day[/code]
Link to comment
Share on other sites

JACKPOT :D

[code]<?PHP
function NoOfDays($Num){

  $years = 0;
  $months = 0;
  $weeks = 0;
  $days = 0;
  $difference=$Num;

  $test = floor($Num/365.25);
  if($test > 0){
  $years = $test;
  $difference = $Num - ($years*365.25);
  }

  $test = floor($difference/30.4);
  if($test > 0){
  $months = $test;
  $difference = $difference - ($months*30.4);
  }

  $test = floor($difference/7);
  if($test > 0){
  $weeks = $test;
  $difference = $difference - ($weeks*7);

  }
  if ($difference >= 1){
  $days = $difference;
  }

  $output = "You have to wait $years Years, $months Months, $weeks Weeks, $days Days until this Day";

  return $output;
}

echo NoOfDays(424);

?>[/code]

I added $difference=$Num; as if no years it wasn't created so of course there is no difference

Thanks Paul :)
Link to comment
Share on other sites

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.