This triggered rule will display a message, if the user is viewing a page of the content type "Exhibition" and the CCK date field is older than the current day:

Add a new triggered rule, call it "Show message when viewing old exhibitions".

Under "Event", select "Node" -> "Content is going to be viewed".

Click "Add a condition" and select "Rules" -> "Numeric comparison"

Copy the "raw date timestamp date" of the field date you want to compare (find it under "CCK date tokens") and insert it into form field "Number 1". Insert the global "raw date timestamp date" in form field "Number 2". Remember to change the drop down between the two form fields to "Less than", like this:

Number 1: [node:field_exhibition_date-timestamp]
Less than
Number 2: [:global:site-date-raw]

Add a second condition: "Viewed content" is "Exhibition", or whatever content type you want this rule triggered.

Add a third condition: "Execute custom PHP code" and enter "return $page;" in "PHP Code:" field, so that the rule is only triggered while you are watching a full node. Otherwise it might also be shown in search results with the content type specified above.

Show a message if the date is older than today: Under "Do", click "Add an action":

"Select an action to add", select "System" -> "Show a configurable message on the site" and enter your "Message", for example: "This is an old exhibition."

Now open up two nodes, one where the date is in the past and one in the future, and verify that the message is only shown on the older node.

Comments

nags338228’s picture

This is fine but what about Drupal 7. I didnt find this

Click "Add a condition" and select "Rules" -> "Numeric comparison"

Can any body give suggestion?

jainparidhi’s picture

When I go to "Add a condition" I cannot find "Rules" -> "Numeric comparison" this either.

Thanks,

PJ

ressa’s picture

Perhaps you can use 'Data comparison' in stead?

jainparidhi’s picture

I initially tried using Data Comparison, but the comparison still returns false. Let me explain my situation:

I have my users enter their graduation_year saved in field_graduation_year. The data type of this year is a Custom Date where I only collect the four digit year (no month day or time). I then want to compare whether the user graduated within the last three years (so that would be comparing it to Y, Y-1, Y-2, Y-3 in php terms for the Date function. But the data comparison value only allows strtotime() which returns an entire Y-M-D-H:M:S format. I have tried every possible scenario, expect physically entering 2012, 2011, 2010, 2009 and once compared, the comparison always returns false.

If I use the custom php code execution condition, my comparison fails again and returns false because the field_graduation_year is of Date type and it cannot be compared to a string year or something. Suppose field_graduation_year contains 2011, and I use the following code:

if([account:field_graduation_year]=="2011") {return TRUE;}

The condition still returns false! What am I doing wrong?

I have been struggling with such a simple condition for the past 3 days! I would really appreciate any help/ feedback!

ressa’s picture

What if you just use a select field, in stead of a Date type field, and manually enter 2009, 2010, 2011, and 2012 in the options? It isn't super elegant, but perhaps it will allow you to make the comparison with custom php?

jainparidhi’s picture

Thats kind of what I did! I am now inputing Year as an integer and have put min values and max values. Can this method be hacked? Are there loopholes that maybe I am not planning for?

Manual years would be a pain, cause I need atleast a span of 100 years. But I could user excel to generate a list and just copy paste it...

Thanks for the tip though!

ressa’s picture

Good that you solved it! Your solution is just as fine as a dropdown. A dropdown would be a tad easier for the user perhaps, but not a lot. Drupal has a very strong security system which is built into Drupal core, so there shouldn't be any issues.