• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 726
  • Last Modified:

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

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
0
dpedersen
Asked:
dpedersen
  • 6
  • 4
1 Solution
 
BogoJokerCommented:
0
 
BogoJokerCommented:
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
0
 
BogoJokerCommented:
This work for you?

Joe P
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
dpedersenAuthor Commented:
Joe,
it shows the days remaining fine, but i need to see hours:minutes:seconds.  can you formated it to show that.  
0
 
BogoJokerCommented:
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
0
 
dpedersenAuthor 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
0
 
dpedersenAuthor 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";


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

Joe P
0
 
BogoJokerCommented:
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?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now