[pmwiki-users] Using PTVs inside php on a page for calculating days difference between dates

kirpi at kirpi.it kirpi at kirpi.it
Sat Sep 27 16:20:31 CDT 2014


> (:input hidden foxfilter number_of_days:)
>
> then  add  to  your  config.php  somewhere  before you include fox.php
> something like this:
>
> $FoxFilterFunctions['number_of_days'] = 'Fox_number_of_days';
> function Fox_number_of_days($pagename, $fields) {
>   $date1 = new DateTime($fields['ptv_Check_in']);
>   $date2 = new DateTime($fields['ptv_Check_out']);
>   $interval = $date1->diff($date2);
>   $fields['ptv_number_of_days'] = $interval->days;
>   return $fields;
> }

Is there any chance that the resulting value will somehow reflect to other PTVs?
Since this filter is in effect, while I get the correct difference in
days inside the relevant PTV, I also experiment a very odd behaviour.
That is: when some other PTVs in the page are empty (not filled in)
AND when these PTVs are used for calculations, such calculations are
processed as if those other variables temporarily assumed the same
value of number_of_days
Also, some other calculated PTVs seem to get the same value.
Which seems quite odd!
:-)

Thanks!

Luigi



More information about the pmwiki-users mailing list