Python 3 Find Difference Between Two Timestamps in Milliseconds

code.py

from datetime import datetime
date_1 = '24/7/2021 11:13:08.230010'
date_2 = '24/7/2021 11:14:18.333338'
date_format_str = '%d/%m/%Y %H:%M:%S.%f'
start = datetime.strptime(date_1, date_format_str)
end =   datetime.strptime(date_2, date_format_str)
# Get the interval between two datetimes as timedelta object
diff = end - start
# Get the interval in milliseconds
diff_in_milli_secs = diff.total_seconds() * 1000
print('Difference between two datetimes in milli seconds:')
print(diff_in_milli_secs)

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.