How to change a column into one date format if you have two different format?

Solution for How to change a column into one date format if you have two different format?
is Given Below:

So, I have a column date with two different date format such as these:

1/2/2011

13-01-2011

I have code :

superstore['Order Month'] = superstore['Order Date'].apply(lambda x: datetime.datetime.strptime(x, "%d/%m/%Y").strftime('%m/%Y'))

Google Colab return

ValueError: time data '13-01-2011' does not match format '%d/%m/%Y'

How to solve this?

Use if statement to check which format is in each entry and apply the correct one. For example:

def convert(x):
    date_format = "%d/%m/%Y" if "https://stackoverflow.com/" in x else "%d-%m-%Y"
    return datetime.datetime.strptime(x, date_format).strftime('%m/%Y')
    
superstore['Order Month'] = superstore['Order Date'].apply(convert)