Support

Account

Home Forums General Issues Comparing Two Date Fields and Using an if Statement Reply To: Comparing Two Date Fields and Using an if Statement

  • You need to compare the different parts. Something line this, I don’t know the exact code here so getting the month in each case is just a guess on my part.

    
    $start_month = $start_date->format('F');
    $end_month = $end_date->format('F');
    if ($start_month == $end_month)) {
      // output July 12-13, 2020
    } else {
      // output July 12 - August 3, 2020
    }
    

    I would probably also make this more complicated, comparing years as well because you might have an event that goes from Dec of one year into Jan of the next.

    
    if ($start_year == $end_year) {
      if ($start_month == $end_month) {
        // output July 12-13, 2020
      } else {
        // output July 12 - August 3, 2020
      }
    } else {
      // output Dec 30, 2019 - Jan 3, 2020
    }