Home > Backend Development > PHP Tutorial > How to calculate the number of days difference between two dates in php, the number of days difference between php dates_PHP tutorial

How to calculate the number of days difference between two dates in php, the number of days difference between php dates_PHP tutorial

WBOY
Release: 2016-07-13 10:03:43
Original
1102 people have browsed it

How to calculate the number of days difference between two dates in php, the number of days difference between php dates

This article describes the method of calculating the number of days difference between two dates in php. Share it with everyone for your reference. The specific implementation method is as follows:

<&#63;php
/**
 * 求两个日期之间相差的天数
 * (针对1970年1月1日之后,求之前可以采用泰勒公式)
 * @param string $day1
 * @param string $day2
 * @return number
 */
function diffBetweenTwoDays ($day1, $day2)
{
  $second1 = strtotime($day1);
  $second2 = strtotime($day2);
   
  if ($second1 < $second2) {
    $tmp = $second2;
    $second2 = $second1;
    $second1 = $tmp;
  }
  return ($second1 - $second2) / 86400;
}
$day1 = "2013-07-27";
$day2 = "2013-08-04";
$diff = diffBetweenTwoDays($day1, $day2);
echo $diff."\n";
Copy after login

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/967741.htmlTechArticleHow to calculate the number of days difference between two dates in php, the number of days difference between php dates. This article tells the example of calculating the difference between two dates in php days method. Share it with everyone for your reference. Specific implementation method...
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