3

我想计算日期前剩余的天数。在我的数据库中,我有一个与结束日期相对应的时间戳。例如星期五 30。我想说这样的话:

还剩 7 天... 6、5、4 等

你能帮我吗 ?

4

5 回答 5

17
$future = strtotime('21 July 2012'); //Future date.
$timefromdb = //source time
$timeleft = $future-$timefromdb;
$daysleft = round((($timeleft/24)/60)/60); 
echo $daysleft;
于 2011-09-23T15:58:54.583 回答
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
于 2015-12-08T08:00:25.297 回答
5
SELECT DATEDIFF(yourtimestamp, CURDATE()) AS days

文档参考:http ://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_datediff

于 2011-09-23T15:58:48.497 回答
5
$days = round((timestamp_from_database - time()) / 86400);
于 2011-09-23T15:59:45.907 回答
-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

于 2018-08-09T13:48:54.183 回答