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
Try to use DateTime function. For your example, is look like:
case 'this_month':
$start_date = new DateTime('first day of this month');
$end_date = new DateTime('last day of this month');
break;
case 'last_month':
$start_date = new DateTime('first day of next month');
$end_date = new DateTime('last day of next month');
break;
echo $start_date->format(DATE_FORMAT);
echo $end_date->format(DATE_FORMAT);
And if you want to get the first and last days of quarter, try to use:
$start_date = new DateTime('first day of January');
$end_date = new DateTime('last day of March');
echo $start_date->format(DATE_FORMAT);
echo $end_date->format(DATE_FORMAT);
Or use function strtotime. Example with strtotime:
$quarter_start = strtotime('first day of January');
$quarter_end = strtotime('last day of March');
echo date(DATE_FORMAT, $quarter_start);
echo date(DATE_FORMAT, $quarter_end);