string to datetime different format python code example
Example 1: converting datetime object format to datetime format python
df['date_time']=pd.to_datetime(df['date_time'], format='%d-%m-%Y %H.%M.%S')
Example 2: fromat date string pyhton
from datetime import datetime
now = datetime.now()
year = now.strftime("%Y")
print("year:", year)
month = now.strftime("%m")
print("month:", month)
day = now.strftime("%d")
print("day:", day)
time = now.strftime("%H:%M:%S")
print("time:", time)
date_time = now.strftime("%m/%d/%Y, %H:%M:%S")
print("date and time:",date_time)