Date range

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #223462
    dave9621
    Participant

    I have an issue with how date ranges are displayed in the events list. I have an event that runs over three days, October 3-5, 2014. But the events list renders that range as “October 3, 2014 – 5”, which is horrible. Is there any way of fixing this, how would we get it to render “October 3-5, 2014”, maybe in a template override or a new function??

    #229546
    Barry
    Member

    Hi – that definitely isn’t ideal, but nor should it display like that out of the box. I see you already ran through the standard recommended troubleshooting steps of deactivating all other plugins and switching to a default, completely unmodified theme. Can you confirm that these steps made no difference to the problem?

    Particularly if you might have added snippets to customize the calendar in your theme’s functions.php file it’s well worth running through these steps.

    #230075
    dave9621
    Participant

    Hi Barry, thanks for helping me. I deactivated all plugins except for Events Calendar and Events Calendar Pro, no affect. I switched to the 2012 theme and that had no affect, still getting the improper date range. I double checked my functions.php and there is no code in there regarding the dates. I did have it in there at one time before upgrading to 3.6, since 3.6 had the date code fix I needed (adding the year no matter if it’s this year or not) in the settings panel I removed it. I have set in the Events settings for the display of “Date without year” to “F j, Y” this is what’s causing the trouble I think. When I make it “F j” then I get “October 23-26” BUT I need it to be “October 23-26, 2014”, we ALWAYS want the year to appear on our dates. Is there a code for that?

    #232397
    Barry
    Member

    BUT I need it to be “October 23-26, 2014″, we ALWAYS want the year to appear on our dates. Is there a code for that?

    It’s definitely possible: if you’re familiar with WordPress’s  hooks and filters you’ll be happy to know there is a filter for just this sort of purpose:

    tribe_events_event_schedule_details

    Your callback could then use tribe_get_start_date() and tribe_get_end_date() to derive the information it needs and build your custom format from there. Does that help?

    #233615
    dave9621
    Participant

    Thanks Barry. Any chance you can give me a little more help? If you point me in the right direction I might be able to figure this out. For instance, in my template override I have the date being displayed by this line of code:
    <?php echo tribe_events_event_schedule_details(); ?>
    Can you give me an example of how to build a callback with the two functions you referenced?

    #235464
    Barry
    Member

    Sure thing – a simple example would look a little like this:

    add_filter( 'tribe_events_event_schedule_details', 'custom_schedule_details' );
    
    function custom_schedule_details() {
    	return tribe_get_start_date() . ' until ' . tribe_get_end_date();
    }

    Do check out the docs for both of those functions – linked to in my last reply – to see how you can specify other formats (you may also want to check out this guide to PHP date/time formatting).

    Good luck 🙂

    #236680
    dave9621
    Participant

    Barry, thanks for the guidance, I finally figured it out. If anyone else is looking for a function that adds the current year and formats the date range if the event is over multiple dates, here’s my code if someone else is looking to solve this issue. Thanks again for you help!

    add_filter( ‘tribe_events_event_schedule_details’, ‘custom_schedule_details’ );

    function custom_schedule_details() {
    /* get the year of the event */
    $endYear = tribe_get_end_date($pageID, false,”Y”);
    /* get the date of the event, only the number, no month or year */
    $endDate = tribe_get_end_date($pageID, false,”j”);
    /* find out if the event is more than one day long */
    if ($endDate != tribe_get_start_date($pageID, false,”j”)) {
    /* if start day and end day are NOT equal then return the date range, including the year */
    return tribe_get_start_date($pageID, false,”F j”) . ‘ – ‘ . $endDate . “, ” . $endYear;
    } else {
    /* if the event is only a single day return the date, including the year */
    return tribe_get_start_date($pageID, false,”F j”) . “, ” . $endYear;
    }
    }

    #238019
    Barry
    Member

    Great – and thank you for sharing the final solution 🙂

    I’ll go ahead and close this thread, but if you have any further questions please do feel free to post new threads as needed. Thanks!

Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘Date range’ is closed to new replies.