Hi,

I am trying to have a date field automatically set for X time in the future using a rules set, but regardless what modifications I make, it always defaults to the current date/time. Here is the code that I am using:

return array(
0 => array('value' => strtotime("+1 day"),
);

As it stands now, when the rules is executed, it populates the field with the current date, not 1 day in the future as I tried to specify in the code. The field I am modifying is a Date field (text field) with the format 30 Aug 2008 00:20. Can anyone help?

(I apologize if this is a simple question, or if my code is simply wrong-I am rather new to PHP. Thanks!)

Comments

Druid’s picture

I can see a code error. You're missing a ) and I'd think you'd get some kind of PHP error message from it:

return array(
0 => array('value' => strtotime("+1 day"))
);

Anyway, get that fixed and see if the behavior changes.

gpy’s picture

Thanks for the tip.

I made the change, however, and it continues to do the same thing. Is strtotime the best way to set the date or are there other methods? I read in a few other issues that the Date module defaults to "now" if the format is not correct, but I have tried other custom formats, as well as converting my change from +1 day to +1440 minutes, but the behavior is always the same.

Any other suggestions? I really appreciate the help.

Druid’s picture

Do you have your TZ (timezone) or PHP 5 timezone properly set? strtotime() is supposed to return a Unix timestamp integer, but depends on knowing your proper timezone. Watch out especially if your server is quite a few timezones away, or is using GMT. I would print out the returned timestamp and see if it is correct (compare it to time() value). If it is 24*3600 larger (correct), check that the correct timezone is used, and how you're using this 'value' later.

gpy’s picture

I'm not sure exactly what to do here. My site timezone is set to US Central, and the date field is set to use the user's timezone.

tmsimont’s picture

Version: 6.x-2.x-dev » 6.x-2.7

I'm seeing the exact issue, setting the value of the field either with php code (I've tried like 5 different ways..) and with a string input on a textfield within the rules module. I don't know if it's rules or me or what, but it's driving me nuts. Was there ever resolution to this? I am seeing this in 6.x-2.7, setting the field value with a rule.

edit: rather than revive an old issue, i've opened a new one that is more specific to the issue in rules:
http://drupal.org/node/1118854

notluap’s picture

I am also having this issue. Setting a cck date field via php with rules, the cck date field always spouts out the current time.

DamienMcKenna’s picture

Component: Date CCK Field » Code
Issue summary: View changes
Status: Active » Closed (outdated)

We're sorry but the D6 release of Date module is no longer being supported. You are encouraged to update to Drupal 7 or 8, or direct questions to Drupal Answers.