I posted this in main forum but afraid I'm not going to get any play on it.. I don't know if it's a bug or just my bad drupal skills.

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

Passionate_Lass’s picture

I'm interested for an answer for this as well since I need the date field to get todays date as well. :)

So a how to get todays date would be helpful. :)

tpainton’s picture

I found this post but it's not working for me.

http://drupal.org/node/491506

I basically have a flag triggered action. Action is custom php code..

$node->field_discharge_date[0][value] = $date("d/m/y");
return array('node' => $node);

I don't know php very well. I do know the value has to be d/m/y so I am trying to pass that to it. sigh. Maybe you can run with this?

tpainton’s picture

FINALLY!

Used the following php in the custom area of "Add value to a field" action.

 // Produce current date
$form_date = date("d,m,y");

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

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

Category: support » bug

Spoke too soon. The returned date is 01/01/09. This despite the content types default value being blank. I am going to change this to a bug instead of a support request. let me know if I am wrong.

tpainton’s picture

Status: Active » Closed (fixed)

My God. This is one of those moments when I could wring someone's neck. 4 days, at least 50 hours on this stupid thing and I finally figured it out..

All someone had to do was tell me that the format for passing a date to a date field HAD to be in ISO. The correct code is..

// 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;