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

on
Medium Priority
755 Views
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

## View Solution Only

Commented:
Commented:
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.

Commented:
This work for you?

Joe P

Commented:
Joe,
it shows the days remaining fine, but i need to see hours:minutes:seconds.  can you formated it to show that.

Commented:
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

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

Commented:
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";

}
?>

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

Commented:
Sure

Joe P

Commented:
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?
##### Thanks for using Experts Exchange.

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