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 in ‘relative date format’. 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.

Current time:
Saturday 21st December 2024, 4:38pm (UTC)

"second weeks":
4th January 2025, 4:38pm (UTC)

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.

  • ondate
  • event_start_after
  • event_start_before
  • event_end_after
  • event_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', 
         )); ?> 

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+

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]