Check if two fields are equal to each other in php

I’m currently working on a website for a gallery that would have exhibitions grouped in collections by year. The format for writing the dates of the exhibitions is something like:

“September 13–December 10, 2020”
and for a few exhibitions it overlaps over two years, so
“December 13, 2020–January 11, 2021”

Maybe this isn’t the best way to do it, but I have separate fields for the ‘starting year’ and ‘ending year’ and the collection is grouped by start year. However, I’d only like to echo the starting year in the php ONLY if it’s different from the ending year, so I don’t get repeats like “September 13, 2020–December 10, 2020”.

I thought something like this would work

<?php if($item->yearstart() != $item->yearend()): ?>, <?= $item->yearstart() ?><?php endif ?>

But somehow it doesnt… is there something I’m doing wrong, or perhaps a better way to approach this?

Thank you in advance!

<?php if($item->yearstart()->value() !== $item->yearend()->value()): ?>, <?= $item->yearstart() ?><?php endif ?>

Ahh so simple! Thanks so much for the quick reply :slight_smile: