How do I change a string like "0/0" to a date form?

Asked 2 years ago, Updated 2 years ago, 141 views

I'd like to change strings such as "January 20th" to a date form, but I think it'll be difficult to use strptime() because the form has no zeros in front of it like July 4th. Can't we simply change strings like this?

date string convert datetime strptime

2022-09-20 19:17

1 Answers

>>> for sin [20 January 2020, 4 July 2020]:
    print(s, datetime.datetime.strptime(s, "%Y year %month %d"))


January 20, 2020-01-2000:00:00
July 4, 2020-07-04 00:00:00


2022-09-20 19:17

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.