Skip to content Skip to sidebar Skip to footer

Int To Datetime In Python

I'm receiving data from the port. This data has date and time.But not formatted. Example: '02012019', '090253' I want to save it to the database and I want to convert this format.

Solution 1:

from datetime import datetime

date_data  ='02012019 09:02:53' 
data = datetime.strptime(date_data,'%d%m%Y %H:%M:%S')
result = data.strftime('%d-%m-%Y %H:%M:%S')

# output '02-01-2019 09:02:53'

Post a Comment for "Int To Datetime In Python"