3

I have an entry that has a date. If it starts and ends on the same day, it should only display the day. Like 'September 21, 2013'.

But right now, my code has it like this:

<strong>Date:</strong> {entry_date format='%F&nbsp;%j'}&mdash;{expiration_date format='%j'}, {expiration_date format='%Y'}<br />

Which pushes out September 21-21, 2013. Is there a way I can modify my code where it would show a single date if the event doesn't stretch over multiple days?

8

Try this:

{entry_date format='%F %j'}{if "{entry_date format='%Y%m%d'}" != "{expiration_date format='%Y%m%d'}"}—{expiration_date format='%j'}{/if}, {expiration_date format='%Y'}
1

Might be overkill but another option would be something like Encaf's double date which I've found to be handy on a few projects.

0

Both entry_date and expiration_date are being stored as UNIX timestamp and also output the same if we don't pass the format parameter. So I think, there is no need to format the entry_date and expiration_date while comparison. It would be simple to write:

{entry_date format='%F %j'}{if entry_date != expiration_date}—{expiration_date format='%j'}{/if}, {expiration_date format='%Y'}

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.