Home > php教程 > php手册 > php计算两个日期相差天数的方法,php日期相差天数

php计算两个日期相差天数的方法,php日期相差天数

WBOY
Release: 2016-06-13 09:12:13
Original
1309 people have browsed it

php计算两个日期相差天数的方法,php日期相差天数

本文实例讲述了php计算两个日期相差天数的方法。分享给大家供大家参考。具体实现方法如下:

<&#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

希望本文所述对大家的php程序设计有所帮助。

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template