Not that I will be able to give a ready-made solution, but I believe that the info in these threads will help you resolve your issues:
Mong others, you will see in these posts how to convert timestamps into milliseconds, which you can then use in any calculation you want.