How to get date and time corresponding to a particular bar and calculate difference this and a fixed date and time

I want to calculate implied volatility of options.
For this i need to use days to expiry and us that as input in the IV calculation. Kindly advise how to retrieve time difference between the successive bar and expiry date.

Thank you in advance

This has been covered a number of times for example: Get past yearly gains and here ValueWhen - how to use