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.
Asked
Active
Viewed 4,335 times
1
-
Does this answer your question? [Convert datetime object to a String of date only in Python](https://stackoverflow.com/questions/10624937/convert-datetime-object-to-a-string-of-date-only-in-python) – Trenton McKinney Aug 31 '20 at 19:19
-
Your question is not clear. You want to change a datetime variable to string with specific format. It has nothing to do with SQL and Selenium – Reza Aug 31 '20 at 19:21
-
I am trying to fetch the data using sql from DB in my selenium python project but while printing the data the datetime format is coming as "datetime.datetime(2020, 8, 27, 4, 16, 33)" but I want this date to be retrieved as "YYYY-MM-DD HH:MM:SS" format. Is it possible? – Rahul Sep 01 '20 at 14:13
1 Answers
5
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'

Reza
- 1,945
- 1
- 9
- 17