Relative date formats
Often you don’t want to query events between two set dates, but dates relative in time. For instance you might want to display upcoming events this month, or events just finished, etc.
Event Organiser allows you to give certain date-related query arguments ‘relative dates’. For example, ‘tomorrow‘, ‘now‘, ‘+1 week‘, ‘third Thursday of this month‘ etc.**
So What’s Allowed?
The interpretation of relative strings is done via native php functions, so a full list of available formats can be found here. Please note which relative statements are available to you depends on the php version you are running WordPress on.
Usage
The relative statements can be used for the appropriate parameters in eo_get_events (or in general an appropriate, WP_Query query) or in the event list shortcode.
ondateevent_start_afterevent_start_beforeevent_end_afterevent_end_before
For example:
//Events running in the coming week..
<?php $events = eo_get_events(array(
'event_end_after'=>'now',
'event_start_before'=>'+1 week',
)); ?>
No time…
Please note that while relative statements like ‘+1 hour’ are allowed, currently only dates are queried. Thus for 23 hours of the day, ‘+1 hour‘ will be interpreted just the same as ‘now‘ and ‘today‘.
PHP Version
Please note that these strings are interpreted using PHP’s datetime object. See allowed statements here. Some PHP versions do not support all the statements.
For example ‘first day of this month‘ is only supported by PHP 5.3+
Change Log
- Since 1.2.2
Examples
Events running from today until two months time
<?php $events = eo_get_events(array(
'event_end_after'=>'now',
'event_start_before'=>'+2 month'
)); ?>
Events running this week (Monday to Sunday)
<?php eo_get_events(array(
'event_end_after'=>'last Monday',
'event_start_before'=>'this Sunday',
'showpastevents'=>1
)); ?>
Using the shortcode to list past events
[eo_events event_end_before="today" showpastevents=true ]
Using the shortcode to list events running this month
[eo_events event_start_before="last day of this month" event_end_after="first day of this month" showpastevents=true]
Using the shortcode to list events starting this month
[eo_events event_start_before="last day of this month" event_start_after="first day of this month" showpastevents=true]