我想计算一个日期之前剩余的天数。在我的数据库中,我有一个与结束日期相对应的时间戳。例如星期五30号。我想说出类似的话:
剩下7天...... 6,5,4等
你能帮我吗?
答案 0 :(得分:10)
$future = strtotime('21 July 2012'); //Future date.
$timefromdb = //source time
$timeleft = $future-$timefromdb;
$daysleft = round((($timeleft/24)/60)/60);
echo $daysleft;
答案 1 :(得分: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
答案 2 :(得分:5)
$days = round((timestamp_from_database - time()) / 86400);
答案 3 :(得分:5)
$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
答案 4 :(得分:-1)
$date1=date_create("2013-03-15");
$date2=date_create("2013-12-12");
$diff=date_diff($date1,$date2);
echo $diff->format("%R%a days");