Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function diffDatesArray($from, $to, $formatInput, $formatOutput) {
- $out = [];
- $fromDate = DateTime::createFromFormat($formatInput, $from);
- $toDate = DateTime::createFromFormat($formatInput, $to);
- $interval = date_diff($fromDate, $toDate);
- $daysInterval = intval($interval->format('%d'));
- for ($i = 0; $i <= $daysInterval; $i++) {
- $nextDay = clone $fromDate;
- if($i >= 1){
- $nextDay->modify('+'.$i.' day');
- }
- $out[] = $nextDay->format($formatOutput);
- }
- return $out;
- }
- $datesArray = diffDatesArray('20/03/2019', '3/04/2019', 'd/m/Y', 'd/m/Y');
- print_r($datesArray);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement