How to fix the datetime in python?

Question:

I am getting an error message that says time data 2017-01-02 13:42:05.378582 does not match format %y-%m-%d %H:%M:%S.%f

start_time = datetime.datetime.strptime(df['timestamp'].min(),'%y-%m-%d %H:%M:%S.%f')
end_time = datetime.datetime.strptime(df['timestamp'].max(),'%y-%m-%d %H:%M:%S.%f')
data_duration = (end_time - start_time).days

print(f"Number of unique users in experiment: {df['user_id'].nunique()}")
Asked By: Ahmed Al Mubarak

||

Answers:

%y is year without century as a zero-padded decimal number (17)

%Y is year with century as a decimal number (2017)

You need: '%Y-%m-%d %H:%M:%S.%f'

Answered By: Yevhen Kuzmovych
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.