I have an array of days in a month excluding friday and sunday as they aren't inculded in policy, i want to convert the array of days names to the dates of the current month but when i convert it is in incorrect format because it shows for different month enter image description here
Asked
Active
Viewed 39 times
1 Answers
1
You can get an array of all the dates you want the following way:
//create a array of DateTimes of the days in the month
$allDateTime = iterator_to_array(new DatePeriod(new DateTime(date('Y-m') . '-1'), new DateInterval('P1D'), new DateTime(date('Y-m-t'))));
//filter out the Fridays and Sundays
$filteredDateTimes = array_filter($allDateTime, function ($date) {
$day = $date->format("N");
return $day !== '7' && $day !== '5'; //7 for sunday, 5 for friday
});
//format the to dd-mm-yyyy
$filteredDates = array_map(function ($date) {
return $date->format("d-m-Y"); //you can choose the format you prefer here
}, $filteredDateTimes);
print_r($filteredDates);
You can run this snippet here: http://sandbox.onlinephpfunctions.com/code/8459152d9020d767110ad2732997af10d2e0d275

Chif
- 830
- 1
- 7
- 20