美文网首页
根据开始时间与结束时间判断是否在同一周

根据开始时间与结束时间判断是否在同一周

作者: 丶Assassin丨 | 来源:发表于2019-06-03 12:13 被阅读0次

    /**

    * Notes: 根据开始时间与结束时间判断是否在同一周

    * 描述: 时间范围判断 周一 至 周日

    * @param string $pretime 开始时间

    * @param string $aftertime 结束时间

    * @return int  是=1 否=2

    * @author 乌索普 add 2019-06-03

    */

    function getSameWeek($pretime, $aftertime)

    {

      // 判断开始时间是否为时间戳

      if(is_int($pretime)){ //开始、结束时间都为时间戳的判断

        $end_timestamp = $aftertime;

        $w = strftime('%u', $pretime);

        $this_sanday_timestamp = $pretime + (7 - $w) * 24 * 60 * 60;

      }else{ //'2019-5-15'

        $begin_timestamp = strtotime($pretime);

        $end_timestamp = strtotime($aftertime);

        $w = strftime('%u', $begin_timestamp);

        $this_sanday_timestamp = $begin_timestamp + (7 - $w) * 24 * 60 * 60;

      }

      //判断结束时间是否在本周

      if ($end_timestamp <= $this_sanday_timestamp) {

        $flag = 1;

      } else {

        $flag = 2;

      }

      return $flag;

    }

    相关文章

      网友评论

          本文标题:根据开始时间与结束时间判断是否在同一周

          本文链接:https://www.haomeiwen.com/subject/twqcxctx.html