dpizd08264 2015-06-24 19:20
浏览 34

使用php datetime对象检查忽略年份的月份和日期

I have 2 date range:

2014/01/28 - 2015/10/10 //first
2015/10/11 - 2014/01/27 //second

How to check using DateTime object in PHP only the month, day and ignoring the year if 2015/06/24 is between first or second date range. The expected answer that 2015/06/24 is between first date range, because 06/24 is between 01/28 - 10/10

Thank you.

  • 写回答

2条回答 默认 最新

  • drkxgs9358 2015-06-24 19:28
    关注
    $date1 = new DateTime("2014/01/28");
    $date2 = new DateTime("2015/10/10");
    $date_compare = new DateTime("2015/06/24");
    
    if ($date_compare->format('m/d') > $date1->format('m/d') &&
    $date_compare->format('m/d') <= $date2->format('m/d')) {
          echo $date_compare->format('m/d') . "fits";
        }
    

    http://php.net/manual/en/datetime.diff.php < this will help you out with this

    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)