How to calculate timediff of two fields in the same event

I don't know ruby so found it very difficult. I have used below post to find the solution.