Remove Month/Year in #_EVENTDATES if date range is same Month/Year

Posted on November 5, 2012

I am getting this: 03 DEC 2012 – 09 DEC 2012

While ideally I would get this: 03 – 09 DEC 2012

add_filter('em_event_output_placeholder','my_em_placeholder_mod',1,3);
function my_em_placeholder_mod($replace, $EM_Event, $result)
{
	if ( $result == '#_EVENTDATES' )
	{
		$day_start = date_i18n('d', $EM_Event->start);
		$day_end = date_i18n('d', $EM_Event->end);

		if ($day_start != $day_end)
		{
			$date_format_start = 'd';

			$year_start = date_i18n('Y', $EM_Event->start);
			$year_end = date_i18n('Y', $EM_Event->end);

			if ($year_start != $year_end)
			{
				$date_format_start .= ' M Y';
			}
			else
			{
				$month_start = date_i18n('M', $EM_Event->start);
				$month_end = date_i18n('M', $EM_Event->end);

				if ($month_start != $month_end)
				{
					$date_format_start .= ' M';
				}
			}

			$replace = date_i18n($date_format_start, $EM_Event->start). ' - ' . date_i18n('d M Y', $EM_Event->end);
		}
	}
	return $replace;
}

Originally submitted here.

Comments are closed.



Interested in Events Manager?

Sign up to our newsletter, receive a free add-on and an additional 10% discount for Pro!

You will receive a confirmation email which you must click on, you will then be sent another welcome email with links to your discount and free add-on.