Advertisement
dimipan80

Lazy Sundays

Dec 2nd, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.56 KB | None | 0 0
  1. // Write a PHP script LazySundays.php which prints the dates of all Sundays in the current month.
  2.  
  3. <?php
  4. function getMonthSundays($currentYear, $currentMonth) {
  5.     $sevenDays = new DatePeriod(
  6.         new DateTime("first sunday of $currentYear-$currentMonth"),
  7.         DateInterval::createFromDateString('next sunday'),
  8.         new DateTime("next month $currentYear-$currentMonth-01")
  9.     );
  10.  
  11.     foreach ($sevenDays as $sunday) {
  12.         echo '<p>' . $sunday->format("jS F, Y") . "</p>\n";
  13.     }
  14. }
  15.  
  16. getMonthSundays(2014, 'August');
  17. getMonthSundays(2014, '12');
  18. getMonthSundays(2015, 4);
  19. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement