I've got a content type with fields: starting date: Date (Unix timestamp) duration: integer ending date: Date (Unix timestamp)

User is setting only starting date (year, month, day) and duration (in days) end after saving the content I would like to automatically calculate ending date (=starting date + duration)

I suppose I should use rules. I tried using actions like set value or calculate value but I failed. Could you help me?

2 Answers 2


Interval module may help you. It provides an interval field type and also a rules action: "Apply an interval to a date".

  • For a negative interval? Feb 9, 2017 at 16:24

For a quick fix I would recommend making a simple custom module with this function:

function YOUR_MODULE_node_presave($node) {
  if($node->type === "your_content_type") { // Replace with the content type of your node.
    // Replace $node->XXX with the actual names of your fields.
    $startdate = $node->start_date[LANGUAGE_NONE][0]['value'];
    $duration = $node->duration[LANGUAGE_NONE][0]['value'];
    $enddate = &$node->end_date[LANGUAGE_NONE][0]['value'];

    $enddate = strtotime('+ ' . $duration . ' days', $startdate);

Your Answer

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

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