Apologies in advance if this question is basic, I’m sure I’m overlooking a straightforward solution.
I’m trying to create a custom template for Pro Reports and have successfully managed to alter the default template for most of my needs. However, I’m struggling to locate or extract a value for the total number of days that the report covers.
For example, for a report covering last month, [report.daterange] token returns ‘August 1, 2024 - August 31, 2024’ which is obviously correct, but I would like to somehow use this information to generate the value ‘31’ for total days in the report for use elsewhere in the template. When next month rolls around, the token will return ‘September 1, 2024 - September 30, 2024’ and I’d like to produce the value ‘30’ for total days, and so on…
I’m not seeing an independent report start or end date anywhere and am unable to manipulate the daterange token to achieve the goal. Is there a way I can accomplish the above that I’m missing? Any help would be greatly appreciated!
Thanks for the welcome and the quick response. I’ve made the switch to MainWP over the last couple of weeks and am really enjoying using it so far - your support in other topics has been very helpful several times already!
Thanks for checking in to this further, looking forward to finding a solution hopefully.
Absolutely superb! Tested with a variety of date ranges and working perfectly. Big thanks to you and the team for the quick solution, top notch.
One very minor adjustment for anyone else stumbling across this topic looking for the same answer. To include start and end date in the calculation, create one further variable:
$datetime1 = new DateTime( date('Y-m-d H:i:s', $report->date_from ) ); // start date
$datetime2 = new DateTime( date('Y-m-d H:i:s', $report->date_to ) ); // end date
$interval = $datetime1->diff($datetime2);
$days = $interval->format('%d') + 1; // Add 1 to include the end date
echo $days;