douzhang1852 2015-12-11 15:34
浏览 80

两天之间的PHP天数计算,包括闰年[重复]

This question already has an answer here:

I am trying to calculate the days between two dates but if I select dates between before 29 Feb or after 29 its coming ok but if I select date between before 29 and after 29 then its giving me wrong days. Here is my code please check how can I fix it ?

$daylen = 60*60*24;
$date1 = '2016-01-01';
$date2 = '2016-03-31';
$numberDays =(strtotime($date2)-strtotime($date1))/$daylen;
</div>
  • 写回答

1条回答 默认 最新

  • doufu1939 2015-12-11 15:36
    关注
    $dStart = new DateTime('2012-07-26');
    $dEnd  = new DateTime('2012-08-26');
    $dDiff = $dStart->diff($dEnd);
    echo $dDiff->format('%R'); // use for point out relation: smaller/greater
    echo $dDiff->days;
    

    Date Difference in php on days? [DUBLICATE]

    http://www.php.net/manual/en/datetime.diff.php

    评论

报告相同问题?

悬赏问题

  • ¥15 BV260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序