获取当前季度的php的startdate和enddate [英] get startdate and enddate for current quarter php

查看:119
本文介绍了获取当前季度的php的startdate和enddate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试按季度设置开始日期和结束日期。

I am trying to set a start date and end date by the quarter.

例如,我正在开发一个报表系统,第1季度,第2季度,第3季度和第4季度。

For example, I am working on a reporting system where i need to report data for quarter 1, quarter 2, quarter 3, and quarter 4.

季度1 - 1月 - 3月

Quarter One - January - March

两到四月 - 六月

季度 - 七月至九月

季度四至十月至十二月

我有例如某些情况下当前月份和前一个月如下所示。

I have for example some cases for the current month, and the previous month as shown below.

   case 'this_month':
      $start_date = date(DATE_FORMAT, mktime(0, 0, 0, date("m"), 1, date("Y")));
      $end_date = date(DATE_FORMAT, mktime(0, 0, 0, date("m"), date("d"), date("Y")));
    break;
    case 'last_month':
      $start_date = date(DATE_FORMAT, mktime(0, 0, 0, date("m") - 1, 1, date("Y")));
      $end_date = date(DATE_FORMAT, mktime(0, 0, 0, date("m"), 0, date("Y")));
    break;

但现在我需要为这个和上一季度添加个案

But now i need to add cases for this and last quarter and I am not sure how to actually do that so it reflects the proper quarter range.

任何想法?

推荐答案

请检查本季度

 case 'this_quarter':

          $current_month = date('m');
          $current_year = date('Y');
          if($current_month>=1 && $current_month<=3)
          {
            $start_date = strtotime('1-January-'.$current_year);  // timestamp or 1-Januray 12:00:00 AM
            $end_date = strtotime('1-April-'.$current_year);  // timestamp or 1-April 12:00:00 AM means end of 31 March
          }
          else  if($current_month>=4 && $current_month<=6)
          {
            $start_date = strtotime('1-April-'.$current_year);  // timestamp or 1-April 12:00:00 AM
            $end_date = strtotime('1-July-'.$current_year);  // timestamp or 1-July 12:00:00 AM means end of 30 June
          }
          else  if($current_month>=7 && $current_month<=9)
          {
            $start_date = strtotime('1-July-'.$current_year);  // timestamp or 1-July 12:00:00 AM
            $end_date = strtotime('1-October-'.$current_year);  // timestamp or 1-October 12:00:00 AM means end of 30 September
          }
          else  if($current_month>=10 && $current_month<=12)
          {
            $start_date = strtotime('1-October-'.$current_year);  // timestamp or 1-October 12:00:00 AM
            $end_date = strtotime('1-January-'.($current_year+1));  // timestamp or 1-January Next year 12:00:00 AM means end of 31 December this year
          }



        break;

更新:2
上一季

case 'last_quarter':

          $current_month = date('m');
          $current_year = date('Y');

          if($current_month>=1 && $current_month<=3)
          {
            $start_date = strtotime('1-October-'.($current_year-1));  // timestamp or 1-October Last Year 12:00:00 AM
            $end_date = strtotime('1-January-'.$current_year);  // // timestamp or 1-January  12:00:00 AM means end of 31 December Last year
          } 
          else if($current_month>=4 && $current_month<=6)
          {
            $start_date = strtotime('1-January-'.$current_year);  // timestamp or 1-Januray 12:00:00 AM
            $end_date = strtotime('1-April-'.$current_year);  // timestamp or 1-April 12:00:00 AM means end of 31 March
          }
          else  if($current_month>=7 && $current_month<=9)
          {
            $start_date = strtotime('1-April-'.$current_year);  // timestamp or 1-April 12:00:00 AM
            $end_date = strtotime('1-July-'.$current_year);  // timestamp or 1-July 12:00:00 AM means end of 30 June
          }
          else  if($current_month>=10 && $current_month<=12)
          {
            $start_date = strtotime('1-July-'.$current_year);  // timestamp or 1-July 12:00:00 AM
            $end_date = strtotime('1-October-'.$current_year);  // timestamp or 1-October 12:00:00 AM means end of 30 September
          }



        break;

这篇关于获取当前季度的php的startdate和enddate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆