generate functionSat, 24 Dec 2022

checks 'Y-m-d H:s:i' if date is today, tomorrow, already passed or anything else

/** * * @param datetime $date_to_check * @param datetime $now * @return string */ function check_date($date_to_check, $now=null) { // setting now if ($now == null) $now = new DateTime(); // get difference $date_to_check = new DateTime($date_to_check); $interval = $now->diff($date_to_check); // checking for today if ($interval->format('%R%a %H %i') == '+0 0 0') { return 'today'; } // checking for tomorrow if ($interval->format('%R%a %H %i') == '+1 0 0') { return 'tomorrow'; } // checking for already passed if ($interval->format('%R%a %H %i') == '-0 0 0') { return 'already passed'; }

Questions about programming?Chat with your personal AI assistant