Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. <?php
  2. function diffDatesArray($from, $to, $formatInput, $formatOutput) {
  3. $out = [];
  4. $fromDate = DateTime::createFromFormat($formatInput, $from);
  5. $toDate = DateTime::createFromFormat($formatInput, $to);
  6. $interval = date_diff($fromDate, $toDate);
  7. $daysInterval = intval($interval->format('%d'));
  8. for ($i = 0; $i <= $daysInterval; $i++) {
  9. $nextDay = clone $fromDate;
  10. if($i >= 1){
  11. $nextDay->modify('+'.$i.' day');
  12. }
  13. $out[] = $nextDay->format($formatOutput);
  14. }
  15. return $out;
  16. }
  17. $datesArray = diffDatesArray('20/03/2019', '3/04/2019', 'd/m/Y', 'd/m/Y');
  18. print_r($datesArray);
  19. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement