I am developing a consultancy website which has event to it. I am using ACF for generating event

Firstly the event consists of 3 things,

  1. Past Events
  2. Ongoing Events + current events + upcoming events

I have successfully generated a Past event and upcoming event for the events post, but my question is I am adding a ribbon for the posts to show is the post is upcoming or ongoing or past or current.

In code I successfully generate a upcoming event and past event, but, I am unable to show the current event and ongoing event in the ribbon

the ribbon is like this

enter image description here

I added the following code to generate these ribbon

                        <div class="ribbon">

                                    $event_date = get_field('event_date');

                                    $events_date = new DateTime($event_date);
                                    $event_timestamp = $events_date->getTimestamp();

                                     if( $event_timestamp <= time()){

                                        $ribbon = "Past Event";

                                        $ribbon = "Upcoming Event";

                                      <span><?php echo $ribbon; ?></span>

for the ongoing event and the current event, there might be some thing which I should add in the above code but I cannot figure it out. Can U guys Please Help me to solve this issue

Note Also for the today date, my ribbon is showing past event and I don't why it is showing this.**

I too research the following stack overflow of these type but none of them work :( https://stackoverflow.com/questions/25622370/php-how-to-check-if-a-date-is-today-yesterday-or-tomorrow

1 Answer 1


Well I Figured it out,

But I have done soo many things that I don't know Is this a good approach or not also I want too simplify my process can anybody help me with this ??

Condition Meets

Suppose Today Date is April 12 - 2021

  • April 9 - April 10 => Past Events
  • April 9 - April 12 => Ongoing Events
  • April 12 - April 18 => Ongoing Events
  • April 15 - April 18 => Upcoming Events
  • April 11 - April 11 => Past Events
  • April 8 - April 18 => Ongoing Events


              $event_start_date = get_field('event_date'); //get event start date
              $event_end_date = strtotime(get_field('event_end_date')); // convert event date to strtotime
              $current_date = date("Y-m-d H:i:s");
              $curr_date=strtotime($current_date); //get current date

                    $the_date=strtotime($event_start_date); //convert event start date to strtotime
                $diff=floor(($curr_date-$the_date)/(60*60*24)); //cal for diff between two strtotime - output on float ie float(-1) or float(1)

                $date_s = date_create($current_date); 

                $date_e = date_create(get_field('event_end_date'));

                $difference_date = date_diff($date_s,$date_e); //get difference of two  dates result is shown on -1 day or 2 day

                $diff_days = $difference_date->format("%R%a"); // get the value of two difference date

if($event_end_date <  $curr_date  ){ // condition to check April-18 < April 12 

                  echo "Past Event";

                        if($diff == 0){ //condition to check April 12 == April 12
                      echo "Today Event";

                    } else if($diff_days == -0){ //condition to check date from April 11 - April  12
                       echo "Ongoing Event";


                }elseif($diff > 1 && $diff > -1 || $diff == 0){ //condition to check date from April 12 - April 18 or April 9 - April 14
                   echo "Ongoing Event";
                }else{ // condtion to check the date above the current date
                  echo "Upcomming Event";
                } ?>

If Any one who can Simplify These codes will be great helpful

Thank You

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.