Last active
November 8, 2022 09:42
-
-
Save ingebrixen/a278bf3c17ab3c9e8073826d784c901a to your computer and use it in GitHub Desktop.
getDateRange
This file contains 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
public function getDateRange() | |
{ | |
$Start = new \DateTime(date('Y-m-d')); // Datum von | |
$dtEnd = new \DateTime(date('m/y')); // Datum bis | |
$dtEnd->modify('first day of next month'); | |
$dtStart = $Start->modify('-1 year'); | |
$period = new \DatePeriod( | |
$dtStart, | |
new \DateInterval('P1M'), // Periode: 1 Monat | |
$dtEnd | |
); | |
$period = array_reverse(iterator_to_array($period)); | |
return $period; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Method to dynamically create a one-year DateRange based on the current month. I use this on my website as a dropdown menu filter to show only the monthly dates selected by the user.
creates:
2021/09
2021/08
2021/07
2021/06
2021/05
2021/04
2021/03
2021/02
2021/01
2020/12
2020/11
2020/10
2020/09
based on the actuall month