Home > Backend Development > PHP Tutorial > How to calculate the number of days until a specified date in php, php date_PHP tutorial

How to calculate the number of days until a specified date in php, php date_PHP tutorial

WBOY
Release: 2016-07-13 09:57:15
Original
896 people have browsed it

How to calculate how many days are left to a specified date in php, php date

The example in this article describes how to calculate how many days are left to a specified date in php. Share it with everyone for your reference. The details are 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;
  }
}
Copy after login

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/984004.htmlTechArticleHow to calculate the number of days until the specified date in php, php date This article tells the example of how many days are left until the specified date in php How many days are there. Share it with everyone for your reference. The details are as follows:...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template