Search
Other Conditional Content questions
Forum

Comparison between custom date field and current date

Didier's Avatar Didier
I use “if” selections with articles anywhere and this works very well.
I would like to combine this with a comparison between a custom date field and the current day.
I suspect this can be done using Conditional Content, but I can't find a simple method, maybe possible with PHP conditions.
For example, I now use: {if selection="closed"}
and would like to add: "and selection-date > today"
With selection and selection-date are custom fields and today is the current date.
A tip if and how this is possible?
Thanks
Didier.
Didier's Avatar Didier
Great, I looked over that, thanks!
Didier.
Didier's Avatar Didier
Hi Peter
Comparing by date seems to work well, also with multiple conditions. But combining AND and OR always seems to produce a true.

Works well:
{if dateswitch <= date('today') AND choicebefore="closed"}

However, always seems to produce a true:
{if dateswitch <= date('today') AND choicebefore="closed" OR dateswitch > date('today') AND choiceafter="closed" }

I expect AND to be processed first and then OR. Adding () does not help either.
Is this possible?
Thanks
Didier.
Peter van Westen's Avatar Peter van Westen ADMIN
Mixing ANDs and ORs like that will give weird results.
Articles Anywhere does not support parentheses inside the {if} tags.

I recommend doing just one type per if tag.
{if dateswitch <= date('today') AND choicebefore="closed"}
[whatever]
{elseif dateswitch > date('today') AND choiceafter="closed"}
[whatever]
{/if}
Please post a rating at the Joomla! Extensions Directory
Didier's Avatar Didier
Thanks Peter, it's very nice that it works this way, just some repetitive code, easily via another Article Anywhere 😊
And another question: I now display today's day and date with some PHP code via Sourcerer, this works perfectly. But since Article Anywhere also uses this information, can't I just show today's day and date via an Article Anywhere call?
Peter van Westen's Avatar Peter van Westen ADMIN
No, Articles Anywhere can only show data from articles. Today's date is not connected to an article.
Please post a rating at the Joomla! Extensions Directory
Didier's Avatar Didier
Scary logical 🙂, thanks Peter for the always super support.
You can only post on the extension support forum if you have an active subscription and you log in

Buy a Pro subscription