The Events Calendar
Countdown to event start date (4 posts)

  1. thirstcard
    Posted 4 years ago #

    I am using tribe_get_start_date(); on my event template to display the event start date.

    I would like to display the number of days to go until the start date. Something like "There are 10 days to go until the event starts on 30 March 2012"

    Is it possible to do this?


  2. bolide
    Posted 4 years ago #

    You'll need a bit of PHP date calculation to get this to work. Google it - it's more complex than it seems. I did this ten years ago using Filemaker and it was easy. It's basically

    "The event starts in (Today-tribe_get_start_date) days"

    If you want to be clever then do this

    If(Today-tribe_get_start_date) >1 "The event starts in (Today-tribe_get_start_date) days"
    else if (Today-tribe_get_start_date) = 1 "The event starts tomorrow"
    else if (Today-tribe_get_start_date) = 0 "The event starts today"
    else if (Today-tribe_get_end_date) >1 "The event is on today"
    else if (Today-tribe_get_end_date) = 0 "the event ends today"
    else if (Today-tribe_get_end_date) <0 "The event has finished"

    In Filemaker I simplified the calculations by using the ISO day number (ie the number of the day in the year) but I think if you do that you'll need to throw in a year check as well so that events don't show up a year later

    Once you figure out the basic calculation all you need then are the else if steps to calculate the result

    This is really useful link:

    Nick Froome

  3. thirstcard
    Posted 4 years ago #

    Thanks Nick I used strtotime

    I have the following working for me:

    <?php if ( ( strtotime(tribe_get_start_date()) < time() ) && ( strtotime(tribe_get_end_date()) < time() ) ) { ?>
    <p>This event has passed.</p>
    <?php } else { ?>
    <?php $day   = tribe_get_start_date(null, false, 'j');
      $month = tribe_get_start_date(null, false, 'n');
      $year  = tribe_get_start_date(null, false, 'Y');
      $hour  = 01;     
      $calculation = ((mktime ($hour,0,0,$month,$day,$year) - time(void))/3600);
      $hours = (int)$calculation;
      $days  = (int)($hours/24); ?>

    then you can just do something like

    <?php echo $days; ?>

  4. Rob La Gatta
    Modern Tribe Support
    Plugin Author

    Posted 4 years ago #

    You guys are proving yourselves as two of the most helpful fellows here on the forum. Thanks again for making it a better experience for the whole community, from us at Modern Tribe. if you'd be willing to share your skillz on the PRO forum I'd be happy to comp you each a free PRO license. Shoot an email to pro /a/ tri.be referencing this thread and we'll hook it up.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • The Events Calendar
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic