Jump to content


Photo

Count Down to Units


  • Please log in to reply
5 replies to this topic

#1 montevi

montevi
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 28 August 2006 - 10:26 PM

Hey all! I am new here so be kind. ;)

I have a little counterscript. I would like to grab the printout presented in years, months, days, hours, minutes, seconds and make them into Unis of 60 minutes and have those count down together with the countdown in time.

Say I have 4 days 5 hours and 2 minutes on the countdown.

then I'd like to add a function that divided tose into hours and present that. How would I go on about doing this?

The script uses mktime.

<?php
// parameters: (year, month, day, hour, minute, seconds)
countdown(2006,8,31,14,0,0);

function countdown($year, $month, $day, $hour, $minute)
{

  $the_countdown_date = mktime($hour, $minute, 0, $month, $day, $year, -1);


  $today = time();

  $difference = $the_countdown_date - $today;
  if ($difference < 0) $difference = 0;

  $days_left = floor($difference/60/60/24);
  $hours_left = floor(($difference - $days_left*60*60*24)/60/60);
  $minutes_left = floor(($difference - $days_left*60*60*24 - $hours_left*60*60)/60);
 
  echo "Today's date ".date("F j, Y, g:i a")."<br/>";
  echo "Countdown date ".date("F j, Y, g:i a",$the_countdown_date)."<br/>";
  echo "Countdown ".$days_left." days ".$hours_left." hours ".$minutes_left." minutes left";
}
?>

Do I need to add another function or could I just add another echo row.. and how would that be written? I am a newbie just trying to figure this out.

I would need to grab the hours and count up and being able to define what hour it should start counting from and print that.


#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 28 August 2006 - 10:33 PM

php scripts execute ONCE on the server and deliver output to the browser, so php isn't really suitable for this.

I think you'll find many, many, examples of javascript countdown timers that will work for you.
Legend has it that reading the manual never killed anyone.
My site

#3 montevi

montevi
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 28 August 2006 - 10:37 PM

No this is exactly what I want. Bt presented in hours sinstead of days etc. :)
I only want it to tick once you load the page.

#4 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 28 August 2006 - 10:39 PM

just multiply the number of days by 24 and add it to the hours.

#5 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 28 August 2006 - 10:41 PM

Then delete the line where days_left is calculated, and delete the reference to days_left in the output.
Legend has it that reading the manual never killed anyone.
My site

#6 montevi

montevi
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 28 August 2006 - 11:30 PM

This is what I did. Thanks for getting me into thinking. I am stupid. I just took the days divided those in 24 and added the hours. And printed days as hours (Units).


  $units_left = floor($difference/60/60/24*24);
  $hours_left = floor(($difference - $units_left*60*60*24/24)/60/60);
  $minutes_left = floor(($difference - $units_left*60*60*24/24 - $hours_left*60*60)/60);

  echo "Today's date ".date("F j, Y, g:i a")."<br/>";
  echo "Countdown date ".date("F j, Y, g:i a",$the_countdown_date)."<br/>";
  echo "Countdown ".$units_left." Units ".$minutes_left." minutes left";
 
To be able to print both info on Days/Hours/Minutes and Units/Minutes I renamed both Hours and Days. But to you this is kidsplay, I am happy it got solved though!
Thank you again. :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users