-2

I need to convert string to date type.What should I do?

My string is "04 Oct 2019". I need to convert to date type "04/10/2019". Note:You can't ignore 0

hunt
  • 15
  • 4

1 Answers1

0
import calendar

def convert_str_to_date(s):
    l = s.split()
    l[1] = "{0:02d}".format(list(calendar.month_abbr).index(l[1]))
    return "/".join(l)

print(convert_str_to_date("04 Oct 2019"))

It won't ignore 0 as "{0:02d}".format

fei ace
  • 11
  • 2