<?php
$query_date = '2010-02-04';
// First day of the month.
echo date('Y-m-01', strtotime($query_date));
// Last day of the month.
echo date('Y-m-t', strtotime($query_date));
// First date of the month.
$monthFirstDate = date('Y-m-01', strtotime('today'));
// Last date of the month.
$monthLastDate = date('Y-m-t', strtotime('today'));
// Second last date of the month
$monthLastSecondDate = date('Y-m-d', strtotime('-2 day', strtotime('today')));
$lastOfMonth = date('Y-m-t');