I want to get a list of timestamps (timezone-aware) for each day of a given month in PHP. So I came up with this script:
$period = new DatePeriod(
new DateTime( date( 'Y-m-d', strtotime( 'first day of august this year' ) ), wp_timezone() ),
new DateInterval( 'P1D' ),
new DateTime( date( 'Y-m-d', strtotime( 'first day of september this year' ) ), wp_timezone() )
);
foreach ( $period as $day ) {
echo $day->format( 'timestamp' );
}
wp_timezone() is a WP function that returns a DateTimeZone Object containing the active timezone of a WP installation, ie. DateTimeZone Object ( [timezone_type] => 3 [timezone] => Europe/Amsterdam )
My problem is that the above script returns an output like this:
310008Europe/Amsterdam0031am08p
310008Europe/Amsterdam0031am08p
...
310008Europe/Amsterdam0031am08p
310008Europe/Amsterdam0031am08p
31 times (obviously for each day of August). What am I doing wrong?