How to calculate time between two actions

I am trying to calculate the time between two actions to push a notification afterwards how long someone was in my home.
I have tried to find some examples but did not find any.

Does anyone have a piston example on how to do so?

Use IBAction function it is every time pressed increases a counter so you can see how many times it’s been pressed