1

I want to display the date an entry has been updated if it is later than the post date. So I've tried this:

   {% if entry.dateUpdated >= entry.post %}
      Updated on {{ entry.dateUpdated.format('j M y') }}
   {% endif %}

But the date updated displays even if it is earlier. Is this because the date is not strictly a value as such?

2

Date fields in Craft are returned as DateTime objects, so you need to convert these to a string to be able to compare them.

The best way of doing this is to use the yyyy-mm-dd format as this makes it is easy to compare dates.

So your comparison would become:

   {% if (entry.dateUpdated|date('Y-m-d')) >= (entry.postDate|date('Y-m-d')) %}
      Updated on {{ entry.dateUpdated.format('j M y') }}
   {% endif %}
2
  • That makes perfect sense. Just for reference there's a missing closing bracket - ie. (entry.postDate|date('Y-m-d'))
    – Andrew
    Nov 16 '20 at 9:47
  • Thanks for picking that up. I've just edited it to correct it. Nov 16 '20 at 9:49
1

You're not checking against a valid field there - try using entry.postDate instead of entry.post

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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