0

I would like to compare the current year with an integer field (let's say a "year of subscription" field) using Rules (if the field value is lower than the current year, the user has no access to a specific action on the website).

I have tried many different things, data comparison, text comparison, PHP custom etc. but I did not manage to create this "apparently" simple condition.

I guess I am missing something (a date/time comparison somewhere? the right PHP code to extract the year of the current date? echo date('YY')? strtotime? mktime?).

Could anyone help me? Thanks in advance.

2

Add the rule as follows:

  1. Event

    Your event

  2. Conditions:

    a. Entity has field

    -> Data Selector = node

    -> Field Value = your date field (mine is field_bp_year)

    b. Execute custom PHP code

    -> Value =

    return intval([node:field-bp-year]) < intval(date("Y"));

    where you add the replacement pattern for your date field (mine was field-bp-year)

  3. Actions:

    Your action

NOTE: I treated my year as four digits. If you only want 2 digits then use date("y").

  • It works for me, thanks for the quick answer. Last thing : if I need Y-1, what would be the PHP syntax? – Toki Apr 21 '16 at 14:29
  • 1
    I always hesitate to use PHP in rules conditions, mostly because I wonder if it has any type of potential securty issues. Any idea about that? – Pierre.Vriens Apr 21 '16 at 15:20

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.