How can one get the timestamps of the first and last minutes of any month using PHP?
With PHP 5.3, you can do
$oFirst = new DateTime('first day of this month');
$oLast = new DateTime('last day of this month');
$oLast->setTime(23, 59, 59);
In PHP 5.2
Note: as AllThecode pointed out in the comments below, this next example only works if you do the $oFirst
portion first. If you add +1 month
to new DateTime
the result will jump an extra month ahead on the last day of the month (as of php 5.5.9).
$oToday = new DateTime();
$iTime = mktime(0, 0, 0, $oToday->format('m'), 1, $oToday->format('Y'));
$oFirst = new DateTime(date('r', $iTime));
$oLast = clone $oFirst;
$oLast->modify('+1 month');
$oLast->modify('-1 day');
$oLast->setTime(23, 59, 59);