<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[FrontAccounting forum — Function to get dates of quarters]]></title>
	<link rel="self" href="https://frontaccounting.com/punbb/extern.php?action=feed&amp;tid=2129&amp;type=atom" />
	<updated>2011-05-29T15:41:18Z</updated>
	<generator>PunBB</generator>
	<id>https://frontaccounting.com/punbb/viewtopic.php?id=2129</id>
		<entry>
			<title type="html"><![CDATA[Function to get dates of quarters]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=9296#p9296" />
			<content type="html"><![CDATA[<p>Hi Guys</p><p>Mucking about modules at the moment, and have just written a versatile function to calculate start/end dates of quarters. With some adjustment to fit naming standards etc. it might be useful to include in date_functions.inc at some point. Hope someone finds it useful!<br />Pete</p><div class="codebox"><pre><code>/**
 * Get last quarter start and end dates for today. Eg. 13/12/2010 = 1/10/2009, 31/12/2009
 * @param array $qtr_dates Referenced array of quarter dates (0=start, 1=end)
 * @param int $num_qtrs How many quarters back/forward (default 0 = this quarter)
 */
function get_quarter_dates(&amp;$qtr_dates, $num_qtrs = 0) {
    // work out the last quarter dates, and store in the qtr_dates array
    include_once($path_to_root . &quot;/includes/date_functions.inc&quot;);
    // 1. Get current month (number)
    $this_month = date(&#039;m&#039;);
    //$this_month = 1; TEST
    // 2. Calculate the start month for this quarter.
    $this_qtr = intval(($this_month - 1)/3) * 3 + 1;
    // 3. Subtract 3 months from this quarter start date to get last quarter
    $qtr_dates[0] = add_months(__date(date(&#039;Y&#039;),$this_qtr,01),$num_qtrs*3);
    // 4. Add two months and get last day of that month for end of last quarter.
    $qtr_dates[1] = end_month((add_months($qtr_dates[0],2)));
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[p2409]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=267</uri>
			</author>
			<updated>2011-05-29T15:41:18Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=9296#p9296</id>
		</entry>
</feed>
