加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

PHP中查询指定时间范围内的所有日期,月份,季度,年份

发布时间:2020-12-13 21:24:49 所属栏目:PHP教程 来源:网络整理
导读:? /* * * 查询指定时间范围内的所有日期,月份,季度,年份 * * @param $startDate 指定开始时间,Y-m-d格式 * @param $endDate 指定结束时间,Y-m-d格式 * @param $type 类型,day 天,month 月份,quarter 季度,year 年份 * @return array */ function ge

?

/**
 * 查询指定时间范围内的所有日期,月份,季度,年份
 *
 * @param $startDate   指定开始时间,Y-m-d格式
 * @param $endDate     指定结束时间,Y-m-d格式
 * @param $type        类型,day 天,month 月份,quarter 季度,year 年份
 * @return array
 */
function getDateByInterval($startDate,$endDate,1)">$type)
{
    if (date('Y-m-d',strtotime($startDate)) != $startDate || $endDate)) != $endDate) {
        return '日期格式不正确';
    }
 
    $tempDate = $startDate;
    $returnData = [];
    $i = 0;
    if ($type == 'day') {    // 查询所有日期
        while ($tempDate) < )) {
            $tempDate = strtotime('+' . $i . ' day',1)">)));
            $returnData[] = $tempDate;
            $i++;
        }
    } elseif ($type == 'month') {     查询所有月份以及开始结束时间
        $temp = [];
            $month = strtotime('first day of +' . $i . ' month',1)">));
            $temp['name'] = date('Y-m',1)">$month);
            $temp['startDate'] = date('Y-m-01',1)">$temp['endDate'] = date('Y-m-t',1)">$temp['endDate'];
            $temp$type == 'quarter') {     查询所有季度以及开始结束时间
        $quarter = $q = ceil(date('n',1)">$quarter) / 3date('Y',1)">$quarter) . '第' . $q . '季度'mktime(0,1)">$q * 3 - 3 + 1,1,1)">$quartermktime(23,59,1)">$q * 3,1)">$i = $i + 3$type == 'year') {     查询所有年份以及开始结束时间
        $year = $i . ' year',1)">$year) . '年'date('Y-01-01',1)">$yeardate('Y-12-31',1)">;
        }
    }
    return $returnData;
}

?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读