Logic Hook / beans date diff

Ok so before we start - yes I know that you can do a calculated field in a workflow - however I am also seeing that the Logic Hook, will always fire before the workflow (even with changing priority).

I have a workflow that runs on a note to calculate how many minutes long the note is. I have a logic hook set that runs after_save so it then goes back to the parent module and calculates total units worked on all notes related to that file.

problem is - it’s skipping the most recent one since the workflow hasn’t fired yet. So I’m back in the logic hook trying to figure out how to do a datediff on the beans side of things and running into no luck. Tried a few of the options suggested in php searches, logic hooks documentation didn’t show me much for calculations there so I figured I’d ask here! Already pulling the start/end times into variables so just need to know syntax here for

datediff($starttime,$endtime,minutes)… Tried a few different ways (calc field requires ; between, php doesn’t like that though) but no luck.

Will keep trying and if I get it before someone answers, will update.

Got it…

take the two date time variables ($startTime and $endTime)
pass them into strtotime options ($startStr = strtotime($startTime), etc).

subtract ($endStr - $startStr) to get the seconds between the two
divide by 60 to get minutes, etc.

1 Like