Jump to content


Photo

Get number of days remaining until a date


  • Please log in to reply
4 replies to this topic

#1 guttyguppy

guttyguppy
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 20 January 2010 - 01:54 AM

Hi, how can I set a variable to contain the number of days left until a future date?


#2 guttyguppy

guttyguppy
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 20 January 2010 - 02:00 AM

GG-here's how:
$future = strtotime('4 July 2010');
$now = time();
$timeleft = $future-$now;
$daysleft = round((($timeleft/24)/60)/60);


#3 guttyguppy

guttyguppy
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 20 January 2010 - 02:00 AM

Thanks Me!

#4 sudeeppgm

sudeeppgm
  • Members
  • Pip
  • Newbie
  • 3 posts

Posted 06 February 2013 - 08:21 AM

<?php

//Convert to date
$datestr="2013-02-06 19:10:18";//Your date
$date=strtotime($datestr);//Converted to a PHP date (a second count)

//Calculate difference

$diff=$date-time();//time returns current time in seconds

$days=floor($diff/(60*60*24));//seconds/minute*minutes/hour*hours/day);

$hours=round(($diff-$days*60*60*24)/(60*60));


//Report
echo "$days days $hours hours remain<br />";echo "<br>";
?>

#5 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 17,842 posts

Posted 06 February 2013 - 09:35 AM

Don't resurrect old threads.

But at least provide an up-to-date solution if you must.

$futureDate = '2013-12-25';
$d = new DateTime($futureDate);
echo $d->diff(new DateTime())->format('%a');  //--> 321


If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users