So, I have Node A. Node A has field_date. which is a date field using the text widget. Custom input format is m/y/d. Pretty simple.

Node A has a flag, and when flagged it triggers Action, Change date.

Change Date action is supposed to update field_date to today's date.

I initially tried using tokens as such.

[node:site-date-dd]/[node:site-date-mm]/[node:site-date-yy]

but when I try to save, I get the following message: Date is invalid.

If I make the value 01/01/09. It works perfectly. But I don't need a static date.. I need today's date. Fine... So tokens are not working. I do have the option for custom php.. So in that box I decide to pass the following code.

$today = date("m/d/y");
return $today

This saves okay but when the action runs field_date doesn't update. My php skills are clearly, very minimal but this has to be possible somehow. I figure I just am not passing the expected value to the date field. Any help, GREATLY appreciated.

Comments

tpainton’s picture

Really needing this to work... If you have done this, would be very appreciative for support. Thanks

tpainton’s picture

Same problem causing a different issue. We would all love to know what the trick is to updating a date field using tokens or php.

http://drupal.org/node/491506

This user has different problem but we both are unable to modify a date field. The reason being the date field doesn't accept tokens (invalid format) or it accepts php but then doesn't pass the value.

tpainton’s picture

Always love being the only one in a thread. Hopefully my stumbling will help someone else eventually..

Found this..

http://drupal.org/node/331000

The poster uses this code as custom php in the action portion of rules to update the date field.

$date = arg(3);
$node->field_date[0][value] = $date;
return array('node' => $node);

When I put this into my custom php however and then try to trigger the rule.. I get a WSOD. Im close.. I think.

tpainton’s picture

I found solution after 3 days of mucking with this. When assigning a date to a date field using php, you have to pass the date as an ISO format. This worked me finally.

// Produce current date
$form_date = date(c);  // NO OTHER FORMAT WORKS!

// Add current date to the expected array
$default_form_date = array (
  0 => array ('value' => $form_date)
);

// return the expected array
return $default_form_date;
looplog’s picture

Can you elaborate on how you got this working? What kind of widget are you using in your date field? How did you setup your rule? Did you use a populate field action? Sorry to be so specific and to bring up an old thread, but I'm having problems with this also...