We are struggling to find a way to calculate a time difference between two dates saved as custom fields on WP. We are actually using two different plugins:
With the first we have created a series of custom fields containing start (ecpt_data-consegna) and end (ecpt_data-dismissione) dates, and we would like to find a way to show the time difference between those dates - shown as XX years, XX months, XX days - in a cell of a table generated through the Advanced Post List plugin. Please note that shall the eding date be missing, the difference should be calculated between the starting date and the current date (now).
After much chatting with both plugins' developers, we came to a standstill. Currently we have developed a custom PHP function to handle the date calculations as follows:
function calculateDiff() {
$start_date = new DateTime(get_post_meta( get_the_ID(), 'ecpt_data-consegna', true ));
$since_start = $start_date->diff(new DateTime(get_post_meta( get_the_ID(), 'ecpt_data-dismissione', true )));
if($since_start->days == 0) {
$since_start = $start_date->diff(new DateTime());
}
return $since_start->y . ' years, ' . $since_start->m . ' months, ' . $since_start->d . ' days'; }
But when we put this APL shortcode inside one of the APL-generated cells:
<td>[php_function name="calculateDiff"]</td>
The result is a broken web page, cut off before the generation of the table itself. And when we try to use this code instead:
<td><?php echo calculateDiff();?></td>
The result is a blank cell.
We have also tried to call the function directly (outside APL) and the result is always a blank. So there must be something wrong somewhere...
Any help would be greatly, greatly appreciated!