When your website means business.

ACF, Date/Time, PHP | Type: PHPDisplay Dates if Start and End Dates Same Month

Handy snippet for displaying event dates when events can stretch over multiple days.

if (!($startdate==$endate)) {
	if ($startdate->format('Y-m') === $endate->format('Y-m')) { //if same month
		echo $startdate->format('F j');
		echo '-';
		echo $endate->format('j, Y');
	} else { //if not same month
		echo $startdate->format('M j');
		echo '-';
		echo $endate->format('M j, Y');
} elseif ($startdate) { // start date and end date are the same date
	echo $startdate->format('D., F j, Y');
We use cookies in order to give you the best possible experience on our website. By continuing to use this site, you agree to our use of cookies.
Cookies Notice