Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

successdav's avatar

Calculate Days to next event

Hi, I am struggling to calculate days to the next event. An event happens every 6 and 21st of the month. So if the current date is 1st of the month then the next event will be held on the 6 of the month and if the current date is above 6 then the next event will be held on the 21st of the month. How Do I check how many days to the next event.

0 likes
2 replies
SilenceBringer's avatar
Level 55

@successdav

$today = today();
$nextEvent = today();

if ($today->day <= 6) {
	$nextEvent->day = 6;
} elseif ($today->day <= 21) {
	$nextEvent->day = 21;
} else {
	$nextEvent->day = 6;
	$nextEvent->month = $nextEvent->month + 1;
}

$difference = $today->diffInDays($nextEvent);
1 like

Please or to participate in this conversation.