当前位置:首页 > PHP > 正文内容

php获取指定日期区间的所有日期,php输出指定范围的所有日期

高老师6年前 (2020-10-13)PHP1292

php输出指定范围的所有日期函数,网上别人封装的,道理很简单,获取最大值和最小值的时间戳,然后+1day即可,测试有效

function periodDate($startDate, $endDate)
{
    $startTime = strtotime($startDate);
    $endTime = strtotime($endDate);
    $arr = [];
    while ($startTime <= $endTime)
    {
        $arr[] = date('Y-m-d', $startTime);
        $startTime = strtotime('+1 day', $startTime);
    }
    return $arr;
}

调用方法:

//获取2021年全年的日期
$allData = periodDate('2021-01-01', '2021-12-31');

输出内容:

array(365) {
  [0]=>
  string(10) "2021-01-01"
  [1]=>
  string(10) "2021-01-02"
  [2]=>
  string(10) "2021-01-03"
  [3]=>
  string(10) "2021-01-04"
  [4]=>
  string(10) "2021-01-05"
  ....
  ....

扫描二维码推送至手机访问。

版权声明:本文由高久峰个人博客发布,如需转载请注明出处。

本文链接:https://blog.20230611.cn/post/169.html

分享给朋友:

“php获取指定日期区间的所有日期,php输出指定范围的所有日期” 的相关文章

PHP使用post发送Json数据

PHP使用post发送Json数据

前公司吃饭是需要在钉钉报餐的,对于不挑剔的我每天都在公司吃饭,有时忘记报餐导致吃不了饭还是很麻烦的。看了下报餐系统需要的是json数据包含我的工号即可。于是编写如下代码,放在360网址监控,1小时执行1次<?php /*自动报餐类*/ class  AutoBaocan{...

抛弃salt,使用password_hash()加密

抛弃salt,使用password_hash()加密

md5/sha1+salt方式是目前各大cms常用的加密方式,虽然salt安全,但是各大md5网站也在研究这个方向,那么我们应该选择password_hash动态hash来助力,一种密码有多种hash结果.看代码模拟登陆.<?php //01.注册 $user ='zhang...

php执行慢原因查找

php执行慢原因查找

今天帮朋友查询wordpress执行超级慢的原因,特此记录开启fpm的慢日志,记录执行超过30秒的脚本request_slowlog_timeout = 30 slowlog = var/log/slow.log查看日志[23-May-2019 17...

windows安装php event扩展问题

windows安装php event扩展问题

php event扩展在windows中依赖于php_sockets扩展,因此在php.ini中必须先加载php sockets扩展,如下。extension=sockets extension=event...

php生成器的send方法详解,php yield send

php生成器的send方法详解,php yield send

【一】.基本用法首先看看官方对send方法的解释:Sets the return value of the yield expression and resumes the generato...

php curl Received HTTP code 403 from proxy after CONNECT

php curl Received HTTP code 403 from proxy after CONNECT

在调用微信code换openid的接口curl报错curl Received HTTP code 403 from proxy after CONNECT,错误码56。可以看到是curl的代理有问题。然后我自己电脑设置代理去访问curl请求的地址,的确也返回了403,说明代理不允许访问这个地址,联系...