doushen1026 2013-04-22 15:02 采纳率: 100%
浏览 127
已采纳

PHP datetime比较天数

I'm comparing dates with this code:

$date1 = new DateTime("2007-03-24 12:10:00");
$date2 = new DateTime("2009-06-26 14:00:30");
$interval = $date1->diff($date2);

If I echo this: echo $interval->m." months and".$interval->d." days."; I get the output 3 months and 2 days.. Now, I want to echo the difference between the dates but include the amount of months in the day count, so a difference of 1 month (with 30 days in it) and 5 days would be 35 days, not 1 month and 5 days. How do I do this?

I'm using PHP version 5.3+.

  • 写回答

2条回答 默认 最新

  • dtye7921 2013-04-22 15:04
    关注

    You should be able to use:

    $interval->days;
    

    See: http://www.php.net/manual/en/class.dateinterval.php#dateinterval.props.days

    echo "There are ".$interval->days." days between the two dates.";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?