I'm trying to create a Drupal View table of CiviCRM activities that calculates the end time of the activity based on start time and duration.

So far I've got the unix start time of the activity, a math expression that turns duration into unix minutes and a math expression that adds the unix start time and the unix duration minutes to get the unix end time of the activity.

The final step is to convert that unix end time of the activity to a human readable time like 7:32 AM. All math expressions work correctly, I've checked the computed end time (expression_1) field with unix converters.

I'm not certain where I'm hitting a wall but if I test the output with the Views PHP module (I'll code it into my template once I get it ironed out) using something like this:

print date('d-M-y g:i A', $row->expression_1);

I get 31-Dec-69 7:00 PM as the output for every row. Which is the day prior to unix's base time of January 1, 1970.

I'd appreciate any guidance.

1 Answer 1


The template file is just to change how this one field is displayed.

Create a view of civicrm activities.
Add the Scheduled Activity Date field three times.
First to display the date.
Second to display the time in.
Third to convert the start date/time to Unix (I had previously added Unix as a time format in Drupal).

Then add Duration.

Add a Math Expression field to convert duration into Unix minutes. enter image description here

Add another Math Expression field to add the Unix start time to the unix duration math expression. enter image description here

Here is the final list of fields:
enter image description here
Save the view.

To create the template for this field we need to get the specific name for the template. In the Advanced section of the View, go to Theme:Information. Scroll though the listed fields until we get to the one we are interested in manipulating.

In our case it was the final field and the most specific template name available (templates are listed from least to most specific). Copy the last listed template.
enter image description here

Now create a new file and paste in the name you just copied. The name should end in tpl.php.

In the file put:

print date("g:i A", $output);

Save this new template to sites/all/themes/current_theme/templates where current_theme is your theme name.

Flush cache and you should be good.

Here is the final result:
enter image description here

Notice that when you are editing the view, this field still displays in Unix time.

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.