Answers.Body: <p>The template file is just to change how this one field is displayed.</p>
  
  <p>Create a view of civicrm activities.<br>
  Add the Scheduled Activity Date field three times.<br>
  First to display the date.<br>
  Second to display the time in.<br>
  Third to convert the start date/time to Unix (I had previously added Unix as a time format in Drupal).</p>
  
  <p>Then add Duration.</p>
  
  <p>Add a Math Expression field to convert duration into Unix minutes.
  <a href="https://i.sstatic.net/n3GwV.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/n3GwV.png" alt="enter image description here"></a></p>
  
  <p>Add another Math Expression field to add the Unix start time to the unix duration math expression.
  <a href="https://i.sstatic.net/FHmbe.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/FHmbe.png" alt="enter image description here"></a></p>
  
  <p>Here is the final list of fields:<br>
  <a href="https://i.sstatic.net/4HJjz.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/4HJjz.png" alt="enter image description here"></a><br>
  Save the view.</p>
  
  <p>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.</p>
  
  <p>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.<br>
  <a href="https://i.sstatic.net/CEd8T.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/CEd8T.png" alt="enter image description here"></a></p>
  
  <p>Now create a new file and paste in the name you just copied. The name should end in tpl.php.</p>
  
  <p>In the file put:</p>
  
  <pre><code>&lt;?php 
  print date("g:i A", $output);
  ?&gt;
  </code></pre>
  
  <p>Save this new template to sites/all/themes/current_theme/templates where current_theme is your theme name.</p>
  
  <p>Flush cache and you should be good.<br></p>
  
  <p>Here is the final result:<br>
  <a href="https://i.sstatic.net/FA9Vc.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/FA9Vc.png" alt="enter image description here"></a></p>
  
  <p>Notice that when you are editing the view, this field still displays in Unix time.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-11T14:51:08.113Z
Answers.LastActivityDate: 2017-03-13T01:56:06.197Z
Answers.LastEditDate: 2017-03-13T01:56:06.197Z
Answers.UserDisplayName: pmoz
Body: <p>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.<p>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.<p>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.<p>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:</p>
  
  <pre><code>&lt;?php
  print date('d-M-y g:i A', $row-&gt;expression_1);
  ?&gt;
  </code></pre>
  
  <p>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.<p>I'd appreciate any guidance.</p>
  
Tags: <drupal><activities><drupal-views><dates>
Title: How to create a Drupal View that calculates activity end time by duration
ThreadText: # How to create a Drupal View that calculates activity end time by duration
  
  (Asked by: username_0 on 2017-03-09)
  
  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:
  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.
  
  **Tags:** drupal, activities, drupal-views, dates
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2017-03-11. Score: 4 | Accepted answer
  
  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.
  
  Add another Math Expression field to add the Unix start time to the unix duration math expression.
  
  Here is the final list of fields:
  
  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.
  
  Now create a new file and paste in the name you just copied. The name should end in tpl.php.
  In the file put:
  
  
  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:
  
  Notice that when you are editing the view, this field still displays in Unix time.
  
  
  ---
  
  