-4
now = datetime.strptime(str(col[4].text), '%d.%m.%Y, %H:%M:%S')

print(type(now))

But the output says that the type of the now variable is: class 'datetime.datetime'

Guys i dont know how to covnert it i propriet fromat, can anyone help?

d_kennetz
  • 5,219
  • 5
  • 21
  • 44
  • [`datetime.strptime`](https://docs.python.org/2/library/datetime.html#datetime.datetime.strptime)'s docs clearly indicate a `datetime` will be returned. What did you expect? – esqew Aug 07 '19 at 18:56
  • What are you asking for? What you are trying to do worked and that's a problem? – Akaisteph7 Aug 07 '19 at 19:00

1 Answers1

1

Datetime objects have a default format when they are printed. The format section of strptime defineds the string format that the datetime STARTS as. Once it is converted to a datetime, it uses the standard representation defined by __repr__ and __str__.

To convert these values to strings in the format that you want, you can use strftime:

now = datetime.strptime(str(col[4].text), '%d.%m.%Y, %H:%M:%S')
now = now.strftime('%d.%m.%Y, %H:%M:%S')

The docs for datetime objects states that print(datetime_object) will return the ISO format representation of datetime_object. ISO format is the YYYY-MM-DD format that you are seeing when printing the datetime.

Read more here: https://docs.python.org/3.2/library/datetime.html

jdub
  • 170
  • 10