daily pastebin goal
61%
SHARE
TWEET

Untitled

a guest Feb 13th, 2018 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. $dateInterval = new \DateInterval('P1M');
  4.  
  5. $datePeriod = new \DatePeriod(
  6.     new \DateTimeImmutable('2016-01-01 00:00:00'),
  7.     $dateInterval,
  8.     new \DateTimeImmutable('2016-02-31 00:00:00')
  9. );
  10.  
  11. echo 'Start: ' . $datePeriod->getStartDate()->format('Y-m-d H:i:s') . PHP_EOL;
  12. echo 'End: ' . $datePeriod->getEndDate()->format('Y-m-d H:i:s') . PHP_EOL;
  13.  
  14. foreach ($datePeriod as $date)
  15. {
  16.     $dateFrom = $date->format('Y-m-d H:i:s');
  17.     $dateTo = $date->add($dateInterval)->format('Y-m-d H:i:s');
  18.  
  19.     echo $dateFrom . ' - ' . $dateTo . PHP_EOL;
  20. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top