-2

I have strings that look like this: "16-Jul-8"

I want to convert them to something like: 16/07/08

datestr = datefields[0]+"-"+datefields[1]+"-"+datefields[2]
dt = datetime.datetime(datestr)
dt.strftime('%d-%m-%y')

I keep coming up empty...

  • Hint Hint - second google result: https://www.google.co.uk/search?sourceid=chrome-psyapi2&ion=1&espv=2&ie=UTF-8&q=python%20change%20date%20format&oq=python%20change%20date%20fo&aqs=chrome.0.0j69i57j0l4.6714j0j1 – Tim Jul 12 '16 at 22:04

1 Answers1

1

it's so easy,

from datetime import datetime
function = lambda date_str: datetime.strptime(date_str, "%y-%b-%d").strftime("%y/%m/%d")
print function("16-Jul-8")

You can read python's documentations from here.

Karl Doenitz
  • 2,220
  • 3
  • 20
  • 38