Stuggling to create a simple rule that compares a commerce checkout field (DOB) with the current date (NOW -18 YEARS) and if not met shows a message
Choosing the operator (less than or greater than seems to show different options and whatever happens when I put in different dates the message either doesn't comeup at all or always comes up - what am I doing wrong please

{ "rules_check_age" : {
    "LABEL" : "Check age",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "commerce_shipping" ],
    "ON" : { "commerce_shipping_collect_rates" : [] },
    "IF" : [
      { "data_is" : {
          "data" : [ "commerce-order:owner:field-date-of-birth" ],
          "op" : "\u003C",
          "value" : {
            "select" : "site:current-date",
            "date_offset" : { "value" : 559872000 }
          }
        }
      }
    ],
    "DO" : [
      { "drupal_message" : { "message" : [ "site:name" ], "type" : "error" } }
    ]
  }
}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

eswiderski’s picture

having similar issue. did you figure this out?

kaztur’s picture

+1

{ "rules_expired_tours_view" : {
    "LABEL" : "My-rule",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "TAGS" : [ "tours" ],
    "REQUIRES" : [ "rules" ],
    "ON" : { "node_view--tours" : { "bundle" : "tours" } },
    "IF" : [
      { "data_is" : { "data" : [ "node:field-tour-date" ], "op" : "\u003C", "value" : "now" } }
    ],
    "DO" : [
      { "redirect" : { "url" : "http:\/\/www.mysite.ru\/tours" } },
      { "drupal_message" : { "message" : "111", "type" : "error" } }
    ]
  }
}
bobfries’s picture

Same. Have noticed rules failing at the date check. It either returns FALSE for every item in the loop or TRUE for every item depending on whether the value check is Greater Than or Less Than.

Anyone got a fix for this yet?

TR’s picture

Additional information about @kaztur's situation in #2, as taken from the duplicate issue #2595955: Data comparison: date doesn't work:

I've tried to create rule which redirects or showing message if node with date field is expired from now.

Creatin a rule:
1. Event: content is viewed of type 'my_type'
2. Condition - tried two conditions:
2.1. Data comparison - Parameter: Data to compare: [node:field-date], Operator: is lower than (also tried is greater than), Data value: [site:current-date]
2.2. Data comparison - Parameter: Data to compare: [node:field-date], Operator: is lower than (also tried is greater than), Data value: now.
3. Action: Show a message on the site bla-bla (also tried redirect).

So nothing happens when I'm viewing node page (both with passed date or the date in future, as admin or as anonymous user).

What I'm doing wrong?