generate functionSun, 27 Nov 2022

php check if given date has passed or is tomorrow or is today or in the future

<?php $date = '2020-09-01'; echo date_passed($date); function date_passed(string $date) { $now = new \DateTime('now'); $date = new \DateTime($date); if($date->diff($now)->invert === 1) { return 'has passed'; } else if ($date->diff($now)->days === 0) { return 'is today'; } else if ($date->diff($now)->days === 1) { return 'is tomorrow'; } else { return 'is in the future'; } }

Questions about programming?Chat with your personal AI assistant