Calculate last month, last 3 months, and last 6 months from today
Try the DateTime class. In combination with the DateInterval class you can do something like this:

$until = new DateTime();
$interval = new DateInterval('P2M');//2 months
$from = $until-&gt;sub($interval);
echo 'from' . $from-&gt;format('Y-m-d') . 'until' . $until-&gt;format('Y-m-d');


Also, you have to set the $until variable only once, before the switch statement.