How to check how many days are left in php

藏色散人
Release: 2023-03-14 14:12:01
Original
2239 people have browsed it

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;
  }
}
Copy after login

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!

Related labels:
php
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