Guest User

weeks in month

a guest
Jun 7th, 2015
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.30 KB | None | 0 0
  1. function weeksInMonth($year, $month, $sunday_first = false) {
  2.     $format = ($sunday_first) ? 'w' : 'N';
  3.     $date   = new DateTime();
  4.     $first  = $date->setDate($year, $month, 1)->format($format) - 1 * (!$sunday_first);
  5.     $days   = $date->format('t');
  6.  
  7.     return ceil(($days + $first) / 7);
  8. }
Advertisement
Add Comment
Please, Sign In to add comment