3v4l.org

run code in 300+ PHP versions simultaneously
<?php $timezone = new DateTimeZone( "UTC" ); $fmj = DateInterval::createFromDateString( 'first Monday of January next year' ); //Monday from start 2019 only $period = new DatePeriod( new DateTime( '2019-01-01 00:00:00.000000', $timezone ), $fmj, new DateTime( '2022-01-11 00:00:00.000000', $timezone ) ); //$period->current= new \DateTime('2019-05-06 00:00:00', new \DateTimeZone('UTC')); $y = 0; foreach ( $period as $dt ) { $c[] = $period; $display[$y++] = $dt->format( "l Y-m-d H:i:s" ); //stop total_recurrence if( $y == 5 ) { break; } } $var = new DateTime( 'first monday of January', new DateTimeZone( "UTC" )); $display[5] = $var->format( "l Y-m-d H:i:s" ); var_dump( $display, $fmj, $c);

preferences:
56.06 ms | 407 KiB | 5 Q