Home >Backend Development >PHP Tutorial >How to calculate the number of days until a specified date in PHP_PHP Tutorial

How to calculate the number of days until a specified date in PHP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 09:57:23908browse

How to calculate how many days are left until a specified date in PHP

This article describes the example of how PHP calculates how many days are left until a specified date. Share it with everyone for your reference. The details are as follows:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

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;

}

}

1 2 3

4

6 7 8 9 10
11 12
13 14 15 16 17 18 19 20 21 22 23 24
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; } }
http://www.bkjia.com/PHPjc/983325.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/983325.htmlTechArticleHow to calculate the number of days until the specified date in php. This article explains how to calculate the number of days until the specified date in php. method. Share it with everyone for your reference. The details are as follows: 1 2 3 4 5...
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