How to query how many days are left in php: 1. Create a PHP sample file; 2. Calculate how many days are left until the specified date through the "function countdays($d){...}" method .
The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.
How to check how many days are left in php?
php method to calculate how many days are left until a specified date
The code is as follows:
function countdays($d) { $olddate = substr($d, 4); $newdate = date(Y) ."".$olddate; $nextyear = date(Y)+1 ."".$olddate; if($newdate > date("Y-m-d")) { $start_ts = strtotime($newdate); $end_ts = strtotime(date("Y-m-d")); $diff = $end_ts - $start_ts; $n = round($diff / 86400); $return = substr($n, 1); return $return; } else { $start_ts = strtotime($nextyear); $end_ts = strtotime(date("Y-m-d")); $diff = $end_ts - $start_ts; $n = round($diff / 86400); $return = substr($n, 1); return $return; } }
Recommended learning: "PHP Video Tutorial 》
The above is the detailed content of How to check how many days are left in php. For more information, please follow other related articles on the PHP Chinese website!