[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2006-03-21
10
Medium Priority
?
705 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
0
Comment
Question by:dpedersen
  • 6
  • 4
10 Comments
 
LVL 17

Expert Comment

by:BogoJoker
ID: 16253894
0
 
LVL 17

Accepted Solution

by:
BogoJoker earned 250 total points
ID: 16253901
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
 
LVL 17

Expert Comment

by:BogoJoker
ID: 16253961
This work for you?

Joe P
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:dpedersen
ID: 16253977
Joe,
it shows the days remaining fine, but i need to see hours:minutes:seconds.  can you formated it to show that.  
0
 
LVL 17

Expert Comment

by:BogoJoker
ID: 16254030
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
 

Author Comment

by:dpedersen
ID: 16254039
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
 

Author Comment

by:dpedersen
ID: 16254103
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
 

Author Comment

by:dpedersen
ID: 16254108
joe p im giving you half points for keeping me focused and interested. and getting me looking in the right track
thanks
0
 
LVL 17

Expert Comment

by:BogoJoker
ID: 16254120
Sure

Joe P
0
 
LVL 17

Expert Comment

by:BogoJoker
ID: 16254129
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

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month20 days, 11 hours left to enroll

865 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question