Skip to content

Instantly share code, notes, and snippets.

@init90
Last active May 4, 2018 20:10
Show Gist options
  • Select an option

  • Save init90/8324d773d502ca5801608e20a1327e86 to your computer and use it in GitHub Desktop.

Select an option

Save init90/8324d773d502ca5801608e20a1327e86 to your computer and use it in GitHub Desktop.
PHP get month interval.
public static function getMonthInterval($date) {
$month_interval = [];
// Get start month date.
$date_obj = new \DateTime($date);
$date_obj->modify('first day of this month');
$month_interval['start'] = $date_obj->getTimestamp();
// Get end month date.
$date_obj->modify('last day of this month');
$date_obj->setTime(23, 59, 59);
$month_interval['end'] = $date_obj->getTimestamp();
return $month_interval;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment