3

I would like to calculate the number of days remaining before a date. In my database I have a timestamp corresponding to the end date. For example Friday 30. I would like to say something like that :

7 days remaining... 6, 5, 4, etc

Can you help me please ?

BobbaFett
  • 63
  • 1
  • 1
  • 4

5 Answers5

17
$future = strtotime('21 July 2012'); //Future date.
$timefromdb = //source time
$timeleft = $future-$timefromdb;
$daysleft = round((($timeleft/24)/60)/60); 
echo $daysleft;
Mob
  • 10,739
  • 6
  • 39
  • 57
9
  $date1 = new DateTime("2016-01-01");  //current date or any date
  $date2 = new DateTime("2016-12-31");   //Future date
  $diff = $date2->diff($date1)->format("%a");  //find difference
  $days = intval($diff);   //rounding days
  echo $days;
  //it return 365 days omitting current day
Muthu Kumar
  • 97
  • 1
  • 1
6
$days = round((timestamp_from_database - time()) / 86400);
Stanislav Shabalin
  • 18,468
  • 3
  • 16
  • 18
Mircea Soaica
  • 2,749
  • 1
  • 13
  • 25
5
SELECT DATEDIFF(yourtimestamp, CURDATE()) AS days

doc ref: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_datediff

Marc B
  • 348,685
  • 41
  • 398
  • 480
-1
$date1=date_create("2013-03-15");
$date2=date_create("2013-12-12");
$diff=date_diff($date1,$date2);
echo $diff->format("%R%a days");

http://php.net/manual/ro/function.date-diff.php

Vitalicus
  • 890
  • 9
  • 14