+ 2

Convert US Date into EU Date[solved]

What is wrong with this program? How do I get its output in the format of 1/1/2024? Its output is coming in the format of 01/01/2024. https://www.sololearn.com/coach/75?ref=app from datetime import datetime def convert_date_to_eu_format(date_str): try: # Parse the input date string date = datetime.strptime(date_str, '%m/%d/%Y') # Convert it to EU format eu_date = date.strftime('%d/%m/%Y') return eu_date except ValueError: try: # If the first attempt fails, try parsing as month name date = datetime.strptime(date_str, '%B %d, %Y') eu_date = date.strftime('%d/%m/%Y') return eu_date except ValueError: return "Invalid date format. Please enter date in MM/DD/YYYY or Month Day, YYYY format." # User input input_date = input() # Convert the date and print the result print(" ", convert_date_to_eu_format(input_date)) Someone help me to fix this. Thanks in Advance

15th Apr 2024, 8:33 AM
Suhani Kewat
6 Answers
+ 1
date = datetime.strptime(date_str, '%m/%d/%Y') d = date.strftime('%d').lstrip('0') m = date.strftime('%m').lstrip('0') eu_date = f"{d}/{m}/{date.strftime('%Y')}" Try with this, hopefully it works!
15th Apr 2024, 12:06 PM
`ᴴᵗᵗየ
`ᴴᵗᵗየ - avatar
+ 4
Thanks ,it's working.
15th Apr 2024, 4:44 PM
Suhani Kewat
15th Apr 2024, 1:29 PM
`ᴴᵗᵗየ
`ᴴᵗᵗየ - avatar
+ 2
No, it's not working.
15th Apr 2024, 1:14 PM
Suhani Kewat
+ 2
Suhani You're welcome ☺️
15th Apr 2024, 4:49 PM
`ᴴᵗᵗየ
`ᴴᵗᵗየ - avatar
+ 1
You can try not to use any module.
15th Apr 2024, 11:03 AM
Wong Hei Ming
Wong Hei Ming - avatar