I'm trying to add a new rule that updates the date within a specific field ("last updated by student") to the current date. The field is a standard CCK Date field with custom input format (yyyy-mm-dd), granularity set to the day.

In Rules, I've created a new triggered rule and set my conditions. But I'm having trouble setting the action "Populate a field". I've tried all of the following variations of tokens in the field;

  • [node:site-date]
  • [node:site-date-yyyy]-[node:site-date-mm]-[node:site-date-dd] (matches my input format)
  • [node:mod-yyyy]-[node:mod-mm]-[node:mod-dd]

But with all of these attempts I always get the error: "Last updated by student is invalid." - and whatever I entered in the field gets replaced with "2009-01-01".

Any pointers toward how I can get this to work would be greatly appreciated!

Comments

itsnotme’s picture

Component: Rules Core » Rules Engine

Not sure we've got the same problem but at least it seems related :)

Tokens didn't work for me at all.

So I tried with

$mydate = date('y-m-d g:i'); 
return $mydate;

but the field still doesn't get filled. I suspect it's got to do with "Content going to be saved" and that the field is already saved before it is attempted to change the value. At least, that seems to be my favorite problem to run into... would also take pointers.

YK85’s picture

subscribing

itsnotme’s picture

Solution:

In the PHP field, the following has to be entered:

$timestamp = time();
return array (
0=> array ('value' => $timestamp),  
);
klausi’s picture

Status: Active » Fixed

Reopen if still an issue.

michellezeedru’s picture

@itsnotme - thank you, that worked perfectly!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

voskuh’s picture

Version: 6.x-1.1 » 6.x-1.4
Status: Closed (fixed) » Active

Hi,

I reopen this issue because I have a support request following this issue. I want to update a date field with a time 15 minutes in future. I tried different php snippets that don't work. The date field is updated to the current date and time and not 15 minutes in future.

The php snippets I used.

$nexttime = time() + (15 * 60);
return array (
0=> array ('value' => $nexttime),  
);

and

$nexttime = strtotime("+15 minutes");
return array (
0=> array ('value' => $nexttime),  
);

Why don't these snippets work? And much more important: how can I achieve what I want? :-)

Thanks in advance

itangalo’s picture

Concerning #7

I think this may be because of the time field you're using -- there are three different date fields, and they might store their values differently. My suggestion is that you install the Devel module, and check the devel tab on a node to see how the date value is stored. Then make your PHP output mimick that.

Good luck!
//Johan Falk
PS: It is generally a good idea to open a new issue rather than re-opening a closed one if it is not the very same issue being discussed.

I'm a part of the Rules Issue Squad, helping out in the issue queue. You can join, too!

itangalo’s picture

Status: Active » Fixed

Oops. Closing.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.