1. ## PHP date calculation

(1)

I need to get the time() value at the start of the current quarter.

Ie. as now is Dec 2008, the system would return the time() value of 1st Oct 2008.

date("Q"); would be great if it did this - but it doesn't.

(2)

I then need to get the time() values for the start of the next 3 quarters
i.e:
Jan-mar 2009
Apr-Jun 2009
Jul-Sep 2009

2. Are you looking for strtotime()? http://www.php.net/strtotime

3. Or something like this can be used to work out the current quarter. You can extend the logic to find next quarters as well.
Code PHP:
```<?php
//quarter's start on first, fourth, seventh, and tenth month
\$quarterMonths = array(1, 4, 7, 10);

//current quarter
\$currentMonth = date('n');
\$currentQuarter = null;
foreach(\$quarterMonths as \$key => \$value){
if(\$value == \$currentMonth){
\$currentQuarter = \$currentMonth;
break;
}
elseif(\$value > \$currentMonth) {
\$currentQuarter = \$quarterMonths[\$key -1];
break;
}
}
\$currentQuarter = \$currentQuarter ? \$currentQuarter : 10;

//so the first day of current quarter is
\$timestamp = mktime(0, 0, 0, \$currentQuarter, 1, date('Y'));
print 'Timestamp: '. \$timestamp;
print 'Date: '. date('F d, Y', \$timestamp);
?>```

4. Nothing but an alternate (umm work around?):
Code php:
```function getQuarters(\$qNums, \$current_date = null){
\$arrQs 		= array();
\$current_m	= (\$current_date != null) ? (int)date('n', strtotime(\$date)) : (int)date('n');
\$current_q 	= ((\$current_m &#37; 3) == 0) ? (\$current_m - 2) : (\$current_m - ((\$current_m % 3) - 1));
\$curr_q_ts 	= strtotime(date('Y') . "-\$current_q-1");
\$arrQs[] 	= date('Y-m-d', \$curr_q_ts);

for(\$i = 1; \$i <= \$qNums; \$i++){
\$arrQs[] = date('Y-m-d', strtotime("+3 months", \$curr_q_ts));
\$curr_q_ts = strtotime("+3 months", \$curr_q_ts);
}
return \$arrQs;
}
\$quarters = getQuarters(3);
echo '<pre>'; print_r(\$quarters); echo '</pre>';```

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•