generate functionFri, 30 Dec 2022

snippet that receives datetime string if it's tomorrow, return 'Tomorrow' If it's after tomorrow, return the amount of days or months that's left If it's today and not passed yet, return the amount of hours/minutes left else, return 'Overdue'

function getDueDate($dateTimeString) { $currentDateTime = new DateTime(); $dueDateTime = new DateTime($dateTimeString); $nowToDueTime = $currentDateTime->diff($dueDateTime); if ($nowToDueTime->invert === 1) { return 'Overdue'; } $days = floor($nowToDueTime->days); if ($days === 0) { return 'Today'; } if ($days === 1) { return 'Tomorrow'; } return $nowToDueTime->format('%y' . ' years and ' . '%m' . ' months'); }

Questions about programming?Chat with your personal AI assistant