duanbei2914 2012-01-17 17:37
浏览 15
已采纳

PHP - 如果日期小于明年1月

I'm to write a function that will return a specific day if it's between two dates... I've been trying to use mktime, but it keeps returning December?

Essentially, I'm trying to do this:

$now = date('F d, Y');

if($now [is Between July of last year and January of next year] ) {

  //Output last day of January in this year

} elseif($now [is Between January of this year and July of this year]) {

  //Output last day of July for next year

}

I'm a little confused on whether I need to be using mktime or strtotime? To determine January of next year, I tried below, but it returned December, 2012?

$jan = date("F,Y", mktime(0, 0, 0, 1, 0, $year+1));
  • 写回答

3条回答 默认 最新

  • dongroufan6846 2012-01-17 17:40
    关注

    Day 0 of January 2012 is actually December 31st of 2011.

    PHP's months are 1-based. Try

    $jan = date("F,Y", mktime(0, 0, 0, 1, 1, $year+1));
                                          ^--- 1st, not 0th
    

    instead.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
  • ¥15 八路抢答器设计出现故障
  • ¥15 请教一下c语言的代码里有一个地方不懂
  • ¥15 opencv 无法读取视频
  • ¥15 用matlab 实现通信仿真
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了