Back to articles
Dates and periods in PHP

Dates and periods in PHP

via Dev.todavid duymelinck

After seeing the following post League Period: A Swiss Army Knife for Time Intervals in PHP Recca Tsai Recca Tsai Recca Tsai Follow Apr 6 League Period: A Swiss Army Knife for Time Intervals in PHP # backend # opensource # php # programming 1  reaction Comments 1  comment 4 min read The deep dive instinct in me wanted to explore more about PHP date handling. The thing that put me over the edge to start it is easter_date . Especially the workaround for the timezone. The basics I hope everyone has moved away from most of the date/time functions and uses the DateTime or even better the DateTimeImmutable classes. $year = 2026 ; $month = 4 ; // old $lastDayOfMonth = date ( 'd' , strtotime ( "last day of $year - $month " )); // new $lastDayOfMonth = new DateTimeImmutable ( "last day of $year - $month " ) -> format ( 'd' ); // alternative $lastDayOfMonth = cal_days_in_month ( CAL_GREGORIAN , $month , $year ); The alternative function comes from the calendar extension . Most of the times this

Continue reading on Dev.to

Opens in a new tab

Read Full Article
2 views

Related Articles