Python 3 Pandas Code to Find the Difference Between Two Datetimes in Milliseconds

main.py

import pandas as pd
from datetime import datetime
date_1 = '2/7/2021 21:55:12.230010'
date_2 = '24/9/2023 11:13:08.333338'
date_format_str = '%d/%m/%Y %H:%M:%S.%f'
start = pd.to_datetime(date_1, format=date_format_str)
end = pd.to_datetime(date_2, format=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.