Trigger a rule based on the time in a date field..

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
wipeout_dude's picture

Hi,

Seem to be a little stuck..

I have content that has a date field with a start and end date and time..

I want a rule to trigger if the node:field-date:value is between 8am and 8:30am.. I have been trying to create a condition of "Data Comparison" where node:field-date:value is greater than "07:59:59" and another condition where node:field-date:value is lower than "08:31:00".. Even running where node:field-date:value is lower than "08:31:00" on it's own doesn't seem to work..

I assume the correct strtotime syntax is simply hh:mm:ss to apply to any date?

Anyone have any ideas?

Thanks..

Comments

A Suggestion ast to the solution

TechnoTim2010's picture

I wasted a couple of days trying to calculate dates, not suspecting that rules had incorporated the new 'relative formats' for datetime. But finally in desperation I set a value to 'first monday of next month' and hey ho it worked. Nice, wish I'd known.

So use the relative formats to set variables and then use data comparison to do the test.

The syntax of php relative formats is here http://www.php.net/manual/en/datetime.formats.relative.php

Good luck but you should find a mechanism that works.

Tim

This did it for me

Falco010's picture

I needed to compare a date field with my site date, the problem was that the site is a date and time. In my data comparison i entered 'today' in my data value and everything was working fine!

Many thanks for this tip!!!

Hi Tim, Yes, I have used the

wipeout_dude's picture

Hi Tim,

Yes, I have used the relative syntax before and it's brilliant but this one has me a little stumped because it doesn't relate to a time from "now" but rather it's relative to the date/time contained in the date field on the node in question..

So if the start date/time in the field of the one node is 2013-12-16 08:00:00 and on another node it's 2013-12-20 08:30:00 the relative "date" will be different but both should evaluate to TRUE because the time is after 07:59:59 and before 08:31:00..

Just hope it doesn't require putting PHP code into the rule because I am rubbish as PHP code.. :)

It may still work

TechnoTim2010's picture

Hi set a variable value using relative dates and you should be ok

The syntax

'front of' hour 1 minute before the specified hour
"front of 8am", "front of 1"
and
back of' hour 30 minutes past the specified hour
"back of 8am", "back of 30"

might work that would set the two variables as 7:59:00 and 8:30:00

Then test the date value against them.

I can tell you that I tried to use a hook_rules_action_info and a hook_rules_condition_info setting the values using date_format and strtotime() it never worked. I could not get a format (even replicating the right date format for a datetime field) to work the date value for a rules variable appears unsettable (or if there is a way noone on IRC or this group knew it).

As I said

Good Luck

Tim

Rules

Group organizers

Group categories

Categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: