zoukankan      html  css  js  c++  java
  • PHP 返回近7天 本月 上月日期

     1 <?php
     2 /**
     3  * 返回近7天,本月,上月数据
     4  * 不计当天(展示后台数据专用)
     5  */
     6 function weekMonthLastMonth($search_date = 'week') {
     7 
     8     switch($search_date)
     9     {
    10         case 'week' : // 近7天
    11             $start_date = date ("Y-m-d", strtotime("-7 days"));
    12             $end_date = date ("Y-m-d", strtotime("-1 days"));
    13             break;
    14         case 'month' : // 本月
    15             $start_date = date ("Y-m-01", strtotime("-1 days"));
    16             $end_date = date ("Y-m-d", strtotime("-1 days"));
    17             break;
    18         case 'last_month' : // 上月
    19             $search_time = strtotime ("-1 month");
    20             $start_date = date ("Y-m-01", $search_time);
    21             $end_date = date ('Y-m-d', strtotime("$start_date +1 month -1 day"));
    22             break;
    23     }
    24     return array($start_date, $end_date);
    25 }
    26 
    27 echo print_r(weekMonthLastMonth('week'), true);
    28 echo print_r(weekMonthLastMonth('month'), true);
    29 echo print_r(weekMonthLastMonth('last_month'), true);
  • 相关阅读:
    Ajax跨域解决实例
    关于tween.js测试介绍
    signal() 和 sigaction()
    信号概述
    监控文件事件
    栈和栈帧
    进程结构和内存布局
    关于文件I/o的原子操作
    查询Linux系统中glibc的版本
    IOPS和Throughput
  • 原文地址:https://www.cnblogs.com/cloudshadow/p/5280431.html
Copyright © 2011-2022 走看看