3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Check if a given date is the first Monday of the month * * @param \DateTime $date * @return bool */ function isFirstMondayayOfMonth(\DateTime $date) { return (int)$date->format('d') <= 7 && $date->format('l') === 'Monday'; } $day = new \DateTime('2013/9/2'); var_dump(isFirstMondayayOfMonth($day)); $day = new \DateTime('2013/10/2'); var_dump(isFirstMondayayOfMonth($day));