Jump to content

Countdown till date


scrupul0us

Recommended Posts

So I've been putzing around with various scipts online to basically just tell me how many:
years months weeks days

are left between now and a given date

ive tried hotscripts and all that jazz but most are insanely bulky or just dont work

e.g... if my event date is August 11 2007 the output should be (based on today august 16 2006):

11 months 3 weeks 5 days

so far ive gotten nothing to work
Link to comment
Share on other sites

try this $until needs to be a timestamp and not a date though, see example at the end ( This is based on months only having 30 days though)

[code]
function formatetimestamp($until){

  $now = time();
  $difference = $until - $now;

  $months = floor($difference/2592000);
  $difference = $difference - ($months*2592000);

  $weeks = floor($difference/604800);
  $difference = $difference - ($weeks*604800);

  $days = floor($difference/86400);
  $difference = $difference - ($days*86400);

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

  return $output;

}

//int mktime ( [int hour [, int minute [, int second [, int month [, int day [, int year [, int is_dst]]]]]]] )

echo formatetimestamp(mktime(0,0,0,12,31,2006)); //output: e.g "You have to wait 5 Months 1 Week 5 Days until this Day"
[/code]

hope that helps
Link to comment
Share on other sites

Hi , Sorry about that maybe I should have checked it before posting it, I have modified it so it works now, here is the code, it takes a date string as the input now in the form of the example at the bottom again
[code]
<?PHP
function formatetimestamp($until){
  $months = 0;
  $weeks = 0;
  $days = 0;

  $now = strtotime("now");
  $difference = $until - $now;

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

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

  $test = floor($difference/86400);
  if ( $test > 0) {
  $days = $test + 1;
  $difference = $difference - ($days*86400);
  }

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

  return $output;

}

echo formatetimestamp(strtotime("31 august 2006"));

?>
[/code]

try it now

again it is not extremely accurate because is predicated on all months having 30 days, to keep it simple, it gives a good idea though
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.