1

Just getting started with Joomla Dates - is there a convenient way to determine what the from/to dates of the last fiscal quarter are?

2

Haven't used JDate for this, but the below PHP code works it for us:

// Current Date
$current_date = date('Y-m-d');
list ($year, $month, $day) = explode('-', $current_date);
$today = new DateTime();
$today->setDate($year, $month, $day);

// This Quarter
$month = $month % 3 ? $month + 3 - ($month % 3) : $month; //
$this_date = new DateTime();
$this_date->setDate($year, $month + 1, 0);
$thisQuarterEnd = $this_date->format('Y-m-d');
$this_date->modify('-2 month');
$this_date->modify('first day of this month');
$thisQuarterStart = $this_date->format('Y-m-d');

// Last Quarter
$last_date = clone $this_date;
$last_date->modify( '-3 month' );
$lastQuarterStart = $last_date->format('Y-m-d');
$last_date->modify( '+2 month' );
$last_date->modify('last day of this month');
$lastQuarterEnd = $last_date->format('Y-m-d');

echo '<br/>Todays Date is '.$today->format('Y-m-d');
echo '<br/>This quarter is  '.$thisQuarterStart . ' thru '.$thisQuarterEnd;
echo '<br/>LAST quarter is  '.$lastQuarterStart . ' thru '.$lastQuarterEnd;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.