获取年份季度的开始和结束日期 [英] Get start and end dates of years quarters

查看:127
本文介绍了获取年份季度的开始和结束日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何获取一年中各季度的开始和结束日期吗?
基本上,我需要当前季度和随后三个季度的开始和结束日期。

does anyone know, how to get the start and end dates of the quarters of a year? Basically I need start and end dates of the current quarter and the following 3 quarters.

我有一个下拉菜单,它的日期应动态填充为看起来像这样:

I have a dropdown and it´s dates should be filled dynamically to look like this:

<select name="quarter-selection">
        <option value="2012-07-01,2012-09-31">Q3 2012</option>
        <option value="2012-10-01,2012-12-31">Q4 2012</option>
        <option value="2013-01-01,2013-03-31">Q1 2013</option>
        <option value="2013-04-01,2013-06-30">Q2 2013</option>
    </select> 

任何帮助都值得赞赏。
thx,
Florian

Any help highly appreciated. thx, Florian

推荐答案

您可以通过以下方法轻松获得它:

You can get it easly with this :

$q1 = array(
    'start' => date('Y-m-d', mktime(0, 0, 0, 1, 1, 2012)),
    'end' => date('Y-m-d', mktime(0, 0, 0, 3, date('t', mktime(0, 0, 0, 3, 1, 2012)), 2012))
);
$q2 = array(
    'start' => date('Y-m-d', mktime(0, 0, 0, 4, 1, 2012)),
    'end' => date('Y-m-d', mktime(0, 0, 0, 6, date('t', mktime(0, 0, 0, 3, 1, 2012)), 2012))
);
$q3 = array(
    'start' => date('Y-m-d', mktime(0, 0, 0, 7, 1, 2012)),
    'end' => date('Y-m-d', mktime(0, 0, 0, 9, date('t', mktime(0, 0, 0, 3, 1, 2012)), 2012]))
);
$q4 = array(
    'start' => date('Y-m-d', mktime(0, 0, 0, 10, 1, 2012)),
    'end' => date('Y-m-d', mktime(0, 0, 0, 12, date('t', mktime(0, 0, 0, 3, 1, 2012)), 2012))
);

这篇关于获取年份季度的开始和结束日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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