我想计算日期前剩余的天数。在我的数据库中,我有一个与结束日期相对应的时间戳。例如星期五 30。我想说这样的话:
还剩 7 天... 6、5、4 等
你能帮我吗 ?
$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
SELECT DATEDIFF(yourtimestamp, CURDATE()) AS days
文档参考:http ://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_datediff
$days = round((timestamp_from_database - time()) / 86400);
$date1=date_create("2013-03-15");
$date2=date_create("2013-12-12");
$diff=date_diff($date1,$date2);
echo $diff->format("%R%a days");