1

I wanted to convert a list containing dates in the format:

01 MAR 2020

Into this format :

2020-03-01 (YYYY-MM-DD) 

using python. Is there a way to do this??

maha
  • 623
  • 5
  • 19
Rohan Limaye
  • 89
  • 1
  • 6

1 Answers1

4

Yes using datetime

from datetime import datetime

# Python object
datetime.strptime("01 MAR 2020", "%d %b %Y")
# datetime.datetime(2020, 3, 1, 0, 0)

# Converted Format
datetime.strptime("01 MAR 2020", "%d %b %Y").strftime('%F')
# 2020-03-01'

PS The locale used might cause problems when dealing with non-numeric months. See here for help on the topic.

niko
  • 5,100
  • 1
  • 10
  • 27