I am trying to set a start date and end date by the quarter.
For example, I am working on a reporting system where i need to report data for quarter 1, quarter 2, qu
Just wanted to point SynaTree's solution doesn't work for every last 3rd month in quarter.
Here's a modified solution using DateTime.
$now = new DateTimeImmutable();
$offset = ($now->format('n') - 1) % 3;
$start = $now->modify("first day of -{$offset} month midnight");
$endExcluded = $start->modify("+3 month");
$endIncluded = $start->modify("+3 month -1 second");
$endExcluded works well when for DatePeriod loops, where the end date is excluded when time is 00:00:00.