Hey all,
Could anyone tell me how to check for the value of just the time (i.e hours, minutes, seconds) in a date field with a rule? Can't figure it out for the life of me...

Thanks in advance!

Comments

Abenezer’s picture

Just bumping this in case it got buried. Thanks in advance!

gettysburger’s picture

Issue summary: View changes

I need the same thing. I am trying to use cron to trigger a rule once a day. Thanks

rashmit sidhu’s picture

I hope that you have time with date field. Your date field is stored in particular entity then you need to customize your rules event info with below.

Step 1 : create custom rule event

function MODULENAME_rules_event_info() {
  return array(
    'event name' => array(
      'label' => t('text'),
      'module' => 'MODULENAME',
      'group' => 'groupname' ,
      'variables' => array(
        'current_user' => array('type' => 'user', 'label' => t('The current logged in user.')),
        'node' => array('type' => 'node', 'label' => t('node object.'))
      ),
    ),
  );
}        

rules_invoke_event('event name', $user, $node);

You require to pass this entity in rule invoke event.

Step 2 : You can access your date field in Execute PHP Code. ie. $node->datefield.

Step 3 : Retrieve Hours, minutes, seconds from above field.

 $datetime = new DateTime(date('Y-m-d H:i:s', 1331875634)); 
        echo $datetime->h.' Hours <br/>'; 
        echo $datetime->i.' Minutes <br/>'; 
        echo $datetime->s.' Seconds <br/>';

Let me know if you face any query/concern regarding this.

Thanks!

tr’s picture

Status: Active » Closed (outdated)