Tribe__Events__Main::previousMonth( string $date )
Given a date (YYYY-MM-DD), return the first of the previous month hat tip to Dan Bernadict for method cleanup
Contents
Parameters
- $date
-
(string) (Required)
Return
(string) Previous month's date
Source
File: src/Tribe/Main.php
public function previousMonth( $date ) { if ( PHP_INT_SIZE <= 4 ) { if ( date( 'Y-m-d', strtotime( $date ) ) < '1902-02-01' ) { throw new OverflowException( esc_html__( 'Date out of range.', 'the-events-calendar' ) ); } } // Create a new date object: a badly formed date can trigger an exception - in such // a scenario try again and default to the current time instead try { $date = new DateTime( $date ); } catch ( Exception $e ) { $date = new DateTime; } // set date object to be the first of the month -- all months have this day! $date->setDate( $date->format( 'Y' ), $date->format( 'm' ), 1 ); // subtract a month $date->modify( '-1 month' ); // return the year-month return $date->format( 'Y-m' ); }