I have a custom-post-type for Vacationperiods where there are some custom fields of type Datepicker to set start and end date. Now I want to get all the days between these to dates and add them to an array.
function get_vacation_dates(){
global $post;
$args = array(
'post_type' => array('vacationperiods'),
'post_status' => array('publish'),
'order' => 'ASC'
);
$posts = get_posts($args);
$vac = [];
foreach ($posts as $post){
$vacationTitle = get_field('name', $post->ID);
$startDate = get_field('vacation_start', $post->ID);
$endDate = get_field('vacation_end', $post->ID);
// GET ALL DAYS/DATES
for ($i=$startDate; $i<=$endDate; $i+=86400) {
$days = date('Y-m-d', $i);
}
$duration = dateDiff($startDate, $endDate);
$vac[] = [
'name' => $vacationTitle,
'start' => $startDate,
'end' => $endDate,
'duration' => $duration,
'days' => $days
];
}
echo json_encode($days);
die();
}
This approach does not work, it gives me "days: '1970-01-01'" - but as mentioned before I want to get all days listed as an array, something like "days: ['2018-09-13', '2018-09-14', etc..]
How can I achieve that?