Conditional based on today's date

  • I am trying to display some text and relevant information from my Events Collection based on todays date.


    I started by writing a system varible in templates/pages/events/detail.php.

    PHP: detail.php
    1. // Set todays date
    2. PerchSystem::set_var('today', date('Y-m-d'));
    3. // Pass date into template
    4. perch_collection('Events', [
    5. 'template' => 'events/event/_enter.html',
    6. ]);

    <perch:showall> confirms that today is avaible for use.


    My Events Collection is quite verbose due to each event having three pricing levels, Early Rate, Reduced Rate and Standard Rate.


    I would like to take the closing day date for the relevant price level, see whether that date is in the past or future, and display the relevant pricing level text.


    I am having issues getting my conditional to display the correct text. Currently it displays the first two if statements, when I was expecting the third.

    events_price_indv_er_cl => 31/10/2019

    events_price_indv_rr_cl => 04/01/2020

    events_price_indv_sr_cl => 30/08/2020


    The way understand the to work is, if date is less than or equal to today's date display the content.


    I'd appreciate some guidance on the conditional as I am clearly not understanding this fully.

  • You can try something like this

    You might have to fiddle to get the comparisons to work, I normally use carbon to handle dates.