Rahul
Rahul

Reputation: 37

Convert datetime format to "YYYY-MM-DD HH:MM:SS" string in Python

I am extracting date from Sql Query executed using selenium Python. The date variable shows up as datetime.datetime(2020, 8, 27, 4, 16, 33) and I need to change the format in "YYYY-MM-DD HH:MM:SS". Please help.

Upvotes: 1

Views: 6155

Answers (1)

Reza
Reza

Reputation: 2025

import datetime
x = datetime.datetime(2020, 8, 27, 4, 16, 33)

x.strftime('%Y-%m-%d %H:%M:%S')

it returns

'2020-08-27 04:16:33'

Upvotes: 5

Related Questions