Jump to content

Count Down to Units


montevi

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.
Link to comment
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. :)
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.