Clac not giving correct answer for only 1 block?

bespokeappstt

Hubstaff freelancer
I am using the calc element to calculate the number of days a resource is out and if it's returned late calculate the number of days it late. If it isn't returned, then calculate the number of days it overdue to be in. The following calculations work just fine:
  1. days overdue if it was returned late
  2. do nothing if the schedule has it out
  3. days overdue if it's late and hasn't been returned.
1 and 2 work fine but I don't know why 3 is giving a huge minus figure. Here is the calc block
Code:
$date1 = time();
$date2 = strtotime('{rad_rentals___due_date_out_raw}');
$date3 = strtotime('{rad_rentals___due_date_in_raw}');
$date4 = strtotime('{rad_rentals___actual_date_in_raw}');
if(($date1 > $date3) && ($date4==0)){
   return ceil(($date1 - $date3) / 86400);  //gives a huge minus figure
}elseif(($date1 > $date3) && ($date4!=0)){
   return ceil(($date4 - $date3) / 86400); //this is fine
} else {
 return 0 ; //this is fine
}

This is what the output looks like
upload_2021-8-17_15-0-29.png

For the first row of data. If today is August 17 2021 then days overdue should be 2 not -738415, because the due date in is August 16 2021. I am troubleshooting a 'php form plugin' code block on serial right now but that shouldn't affect this. It should say 2 for the first row of data. It's possible I have a timezone issue to get around when performing arithmetic between time() and strtotiime() but I'm not sure how to do that.
 
Last edited:
Sorry, but neither Fabrik (J! 2.5 / F 3.0 or whichever) nor its calc element -- but generic PHP and math.
So, with all respect, please understand if you won't find anyone here in the Fabrik support forums taking the time and effort to dig into such generic topic for a specific use case.
There are other forums on the Interwebs for this, and/or people for hire.
 
I understand. I'll leave it open for a bit longer, 2 weeks and then close. Meanwhile I'll troubleshoot and if I get the answer I'll post.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top