开发者

Calculate number of days remaining [duplicate]

This question already has answers here: Finding the number of days between two dates (34 answers) Closed 3 years ago.

I would like to c开发者_运维技巧alculate 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 ?


$future = strtotime('21 July 2012'); //Future date.
$timefromdb = //source time
$timeleft = $future-$timefromdb;
$daysleft = round((($timeleft/24)/60)/60); 
echo $daysleft;


  $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


$days = round((timestamp_from_database - time()) / 86400);


SELECT DATEDIFF(yourtimestamp, CURDATE()) AS days

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


$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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜