Jump to content

Archived

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

montevi

Count Down to Units

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Then delete the line where days_left is calculated, and delete the reference to days_left in the output.

Share this post


Link to post
Share on other sites
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. :)

Share this post


Link to post
Share on other sites

×

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.