Reputation: 121
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??
Upvotes: 1
Views: 81
Reputation: 5281
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.
Upvotes: 4