1

I'm trying to add a time duration field value (integer type representing seconds) to a date field using rules, but I'm not able to reference the duration field when it comes time to calculate/edit the date value (presumably because they are of different field types). I can do things like "+30 days", but really what I want to do is "+$x days".

4 Answers 4

3

The interval module provides an action "Apply an interval to a date" (you find it in the "data"-section of the action list). The module supplies a "interval field", but surprisingly, instead of providing integration between rules and that field, it provides that action, which provides integration between rules and an integer field. The action allows you to specify a data value and specify which interval that number is to be interpreted as (days, months, ...)

1
  • For a negative interval? Feb 9, 2017 at 16:25
2

Thanks to rosell.dk for pointing out the Interval module. Just to expand on that:

First create 2 conditions to check if the 2 fields exist.

Entity has field:
  entity1:field_number_of_days (Integer)
Entity has field:
  entity2:field_date (Date)

Then you need to create TWO rules. First rule:

Apply an interval to a date: 
  Interval Number:    entity1:field_number_of_days
  Interval Period:    days
  Date:               entity2:field_date
  Provided Variables: new_date

However, you're not finished. This stores ( date_field + number_of_days_field ) in a new date value called new_date. In order to save that new date back into date_field you have to create one final rule:

Set a data value:
  Data:  entity2:field_date
  Value: new_date
1

FYI I solved this by invoking a rules hook to change the field to duration. This solution was inspired by fago's commerce subscription products module.

1
  • Would you please care to share with us how you achieved this conversion?
    – Wtower
    May 21, 2014 at 12:40
0

I would also like to hear more information about this. I am trying to create a rule which follows up on existing orders of specific products. Each product has a different time interval for "follow up reminder", and my rule should trigger an email to be sent to a customer at a date which is calculated Order Creation Date + Follow Up Interval.

ie Order Creation + Value provided from Products in the order

5
  • If the current answers to this question do not help in your specific situation, feel free to open a new question with your specific details - you likely will not get much attention in this old thread. Jun 16, 2015 at 17:09
  • Thanks for the insight! I still wanted to share how I solved this problem: I created a rule which is dependent on an Order's Status being "Completed". This rule runs a custom PHP script which loads the Completed order Entity, retrieves each Line item and checks for its field called "Follow-up", which gives a time value in weeks. Jun 30, 2015 at 19:12
  • If that field isn't empty, it runs some code to convert the time into seconds, choose a date value based on the order date + the followup time, and inserts a row into a database for EACH line item which requires a followup service. In order to send out mail for each particular followup, I created a cronjob using crontab directly on the server hosting the project. This simply runs each morning, checks the database to see if any of the rows have a date which matches "today", and subsequently retrieves the relevant information and sends the customer the appropriate followup notice! Jun 30, 2015 at 19:12
  • If anyone wants some more info, snippets, etc, I would be happy to share any part of this code! It is somewhat lengthy, so I didn't want to paste it all. Jun 30, 2015 at 19:12
  • I created a thread for my particular issue, in case that's more helpful/appropriate: drupal.stackexchange.com/questions/163810/… Jun 30, 2015 at 19:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.