源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

PHP简单获取上月、本月、近15天、近30天的方法示例

  • 时间:2022-05-04 14:20 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:PHP简单获取上月、本月、近15天、近30天的方法示例
本文实例讲述了PHP简单获取上月、本月、近15天、近30天方法。分享给大家供大家参考,具体如下:
/**
 * 获取统计时间
 * @param $type
 * 1 上月
 * 2 本月
 * 3 近15天
 * 4 近30天
 * @return array
 */
function getDateInfo($type)
{
  $data = array(
    array(
      'firstday' => date('Ym01', strtotime('-1 month')),
      'lastday' => date('Ymt', strtotime('-1 month')),
    ),
    array(
      'firstday' => date('Ym01', strtotime(date("Y-m-d"))),
      'lastday' => date('Ymd', strtotime((date('Ym01', strtotime(date("Y-m-d")))) . " +1 month -1 day")),
    ),
    array(
      'firstday' => date('Ymd', strtotime("-15 day")),
      'lastday' => date('Ymd', strtotime('-1 day')),
    ),
    array(
      'firstday' => date('Ymd', strtotime("-30 day")),
      'lastday' => date('Ymd', strtotime('-1 day')),
    ),
  );
  return is_null($type) ? $data : $data[$type-1];
}
print_r(getDateInfo(1));//获取上个月第一天与最后一天

运行结果:
Array
(
  [firstday] => 20170601
  [lastday] => 20170630
)

[b]PS:这里再为大家推荐几款时间及日期相关工具供大家参考使用:[/b] [b]在线日期/天数计算器: [/b][url=http://tools.jb51.net/jisuanqi/date_jisuanqi]http://tools.jb51.net/jisuanqi/date_jisuanqi[/url] [b]在线日期计算器/相差天数计算器: [/b][url=http://tools.jb51.net/jisuanqi/datecalc]http://tools.jb51.net/jisuanqi/datecalc[/url] [b]在线日期天数差计算器: [/b][url=http://tools.jb51.net/jisuanqi/onlinedatejsq]http://tools.jb51.net/jisuanqi/onlinedatejsq[/url] [b]Unix时间戳(timestamp)转换工具: [/b][url=http://tools.jb51.net/code/unixtime]http://tools.jb51.net/code/unixtime[/url] 更多关于PHP相关内容感兴趣的读者可查看本站专题:《[url=http://www.1sucai.cn/Special/96.htm]php日期与时间用法总结[/url]》、《[url=http://www.1sucai.cn/Special/623.htm]PHP数组(Array)操作技巧大全[/url]》、《[url=http://www.1sucai.cn/Special/348.htm]PHP基本语法入门教程[/url]》、《[url=http://www.1sucai.cn/Special/43.htm]php面向对象程序设计入门教程[/url]》、《[url=http://www.1sucai.cn/Special/47.htm]php字符串(string)用法总结[/url]》、《[url=http://www.1sucai.cn/Special/84.htm]php+mysql数据库操作入门教程[/url]》及《[url=http://www.1sucai.cn/Special/231.htm]php常见数据库操作技巧汇总[/url]》 希望本文所述对大家PHP程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部