We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Date Difference in day:hours:minutes PHP time remaining from now till future date

dpedersen
dpedersen asked
on
Medium Priority
755 Views
Last Modified: 2008-01-09
Hello, i am a coldfusin prgrammer and got stuck with running a PHP auction....i need to show time remaining in hours:minutes:seconds from now til future date

eg,
from current server time  to April 31, 2006 @ 8:00 pm.  

can someone help me.  

thanks
Comment
Watch Question

Here is the code from that tutorial:

<?php
// Change this to the day in the future
$day = 8;
// Change this to the month in the future
$month = 31;
// Change this to the year in the future
$year = 2006;
// $days is the number of days between now and the date in the future
$days = (int)((mktime (0,0,0,$month,$day,$year) - time(void))/86400);
echo "There are $days days until $day/$month/$year";
?>



Joe P

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
This work for you?

Joe P

Author

Commented:
Joe,
it shows the days remaining fine, but i need to see hours:minutes:seconds.  can you formated it to show that.  
The 0,0,0 in mktime stands for hours, minutes, seconds
<?php
// Change this to the day in the future
$day = 8;
// Change this to the month in the future
$month = 31;
// Change this to the year in the future
$year = 2006;
// $days is the number of days between now and the date in the future
$days = (int)((mktime (20,0,0,$month,$day,$year) - time(void))/86400);
echo "There are $days days until $day/$month/$year";
?>

Try that

Joe P

Author

Commented:
ive made these changes to the code
<?php
// Change this to the day in the future
$day = 31;
// Change this to the month in the future
$month = 4;
// Change this to the year in the future
$year = 2006;
$hour = 20;
$minute = 00;
$second = 00;
// $days is the number of days between now and the date in the future
$days = (int)((mktime ($hour,$minute,$second,$month,$day,$year) - time(void))/3600);
echo "There are $days minutes until $month/$day/$year @ $hour:$minute:$second";
?>

this outputs remaining minutes however, i want the output formated to appear like this

30 days, 12 hours, 36 minutes , 4 seconds remaining

can you do that

Author

Commented:
i answered my own question
i found this on the web

<?php
// countdown function
// parameters: (year, month, day, hour, minute)
countdown(2006,4,31,20,00);

//--------------------------
// author: Louai Munajim
// website: www.elouai.com
//
// Note:
// Unix timestamp limitations
// Date range is from
// the year 1970 to 2038
//--------------------------
function countdown($year, $month, $day, $hour, $minute)
{
  // make a unix timestamp for the given date
  $the_countdown_date = mktime($hour, $minute, 0, $month, $day, $year, -1);

  // get current unix timestamp
  $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);
  $seconds_left = floor(($difference - $days_left*60*60*24 - $hours_left*60*60 - $minutes_left*60));
 
  // OUTPUT
echo "There are $days_left Days, $hours_left Hours and $minutes_left Minutes, $seconds_left seconds until $month/$day/$year @ $hour:$minute:$second";


}
?>

Author

Commented:
joe p im giving you half points for keeping me focused and interested. and getting me looking in the right track
thanks
Sure

Joe P
http://www.experts-exchange.com/help.jsp#hi75
I would have liked the chance to earn at least a B grade.  Any clarification on my part, further instruction that would have warrented at least a B grade?
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.