Home  >  Article  >  Backend Development  >  How to check how many days are left in php

How to check how many days are left in php

藏色散人
藏色散人Original
2021-12-17 10:44:202224browse

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 .

How to check how many days are left in php

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!

Statement:
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