Last active
May 2, 2020 15:59
-
-
Save isu3ru/17d7714be8102ac4fe19b681d0b76c8e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function getNextDays($day = 'Tue', $count = '+2', $type = 'months') { | |
// current date | |
$today = date('Y-m-d'); | |
// add 2 months to date | |
$twoMonthsLater = date('Y-m-d', strtotime(sprintf('%s %s', $count, $type))); | |
// set begin date of the range (today or any other date) | |
$begin = new \DateTime($today); | |
// set the end date of the range | |
$end = new \DateTime($twoMonthsLater); | |
// create interval | |
$interval = new \DateInterval('P1D'); | |
// create date period | |
$daterange = new \DatePeriod($begin, $interval, $end); | |
// collect | |
$days = []; | |
foreach ($daterange as $date) { | |
if ($date->format('D') == $day) { | |
$d = $date->format("Y-m-d"); | |
$days[$date->format("Ymd")] = [ | |
'date' => $d, | |
'text' => $date->format('l jS \of F, Y') | |
]; | |
} | |
} | |
return $days; | |
} | |
public function getNextDaysFrom($startDate = '2020-05-10', $day = 'Tue', $count = '+2', $type = 'months') { | |
// current date | |
$start = strtotime($startDate); | |
$today = date('Y-m-d', $start); | |
// add 2 months to date | |
$twoMonthsLater = date('Y-m-d', strtotime(sprintf('%s %s', $count, $type), $start)); | |
// set begin date of the range (today or any other date) | |
$begin = new \DateTime($today); | |
// set the end date of the range | |
$end = new \DateTime($twoMonthsLater); | |
// create interval | |
$interval = new \DateInterval('P1D'); | |
// create date period | |
$daterange = new \DatePeriod($begin, $interval, $end); | |
// collect | |
$days = []; | |
foreach ($daterange as $date) { | |
if ($date->format('D') == $day) { | |
$d = $date->format("Y-m-d"); | |
$days[$date->format("Ymd")] = [ | |
'date' => $d, | |
'text' => $date->format('l jS \of F, Y') | |
]; | |
} | |
} | |
return $days; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment