from datetime import datetime as dt # from string datetime = dt.strptime('2022-01-01 23:59:59', '%Y-%m-%d %H:%M:%S') # to string print(datetime.strftime("%Y-%m-%d %H:%M:%S"))