Here is the code that worked for me in case someone else finds it helpful
<?php
// Set the timezone to Berlin
date_default_timezone_set('Europe/Berlin');
// Get the start date from Kirby
$startdate = $page->startDate()->toDate('Y-m-d'); // Using 'Y-m-d' format for accurate comparison
// Convert the start date to a DateTime object
$startDateTime = new DateTime($startdate);
// Get the current date without the time component
$today = new DateTime('today');
// Calculate the difference between the start date and today
$interval = $startDateTime->diff($today);
$daysDifference = $interval->days;
// Get the day of the week for the start date
$startDayOfWeek = (int)$startDateTime->format('N'); // 1 (Monday) through 7 (Sunday)
// Output the label based on the difference and day of the week
if ($daysDifference == 0) {
echo 'today';
} elseif ($daysDifference == 1) {
echo 'tomorrow';
} elseif ($daysDifference <= 7 && $today->format('N') < $startDayOfWeek) {
echo 'this week';
} elseif ($daysDifference <= 13) {
echo 'next week';
} elseif ($startDateTime > $today) {
echo 'upcoming';
}
?>