Viewing 3 replies - 1 through 3 (of 3 total)
  • 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:
    https://www.the-art-of-web.com/php/strtotime/

    Nick Froome

    Thread Starter thirstcard

    (@thirstcard)

    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; ?>

    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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: The Events Calendar] Countdown to event start date’ is closed to new replies.