-1

I'm stuck with this python problem, I have a date in the format of month-day-year and I need to change it to year-month-day format

rteja1113
  • 21
  • 2

1 Answers1

1
>>> import datetime
>>> datetime.datetime.strptime("06/03/2015", "%m/%d/%Y").strftime("%Y-%m-%d")
'2015-06-03'

This takes a date (June 3, 2015 in this case) as a string and parses it to a datetime object using strptime. It then converts that to a string in the format you requested (YYYY-mm-dd) using strftime

Andy
  • 49,085
  • 60
  • 166
  • 233