Skip to content

Commit 664fbc5

Browse files
committed
Edit - Correct Convert date. Remove padded zeros.
1 parent f7b8d63 commit 664fbc5

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

Python/Convert_US_Date_to_EU_Date.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,26 @@
3131
# Import the regex package
3232
import re
3333

34-
# Import the time package
34+
# Import the datetime package
3535
from datetime import datetime
3636

37+
# Use regex to identify if the first character of the input is a capital letter (first letter of a month)
3738
USDateStrRe = re.match(r'[A-Z]',USDateStr)
39+
40+
# Use dateime.strptime to create a date object based on the result of the regex match.
3841
if (USDateStrRe is None):
39-
#date is 11/19/2019 format
42+
# If there was no result from the Regex search, date is 11/19/2019 format
4043
USDate = datetime.strptime(USDateStr,'%m/%d/%Y')
4144
else:
42-
#date is in November 19, 2019 format
45+
# If there there was a result from the Regex search, date is in November 19, 2019 format
46+
# %B is the full month name
4347
USDate = datetime.strptime(USDateStr,'%B %d, %Y')
4448

45-
EUDate = datetime.strftime(USDate,'%d/%m/%Y')
49+
# Use dateime.strftime to convert the date object into a string of the required formate.
50+
# To remove the leading zeros from the date (as required by the puzzle) on Linux/Android, use a hyphen between the % and the letter code. (This is the solution that will run on Sololearn)
51+
EUDate = datetime.strftime(USDate,'%-d/%-m/%Y')
52+
53+
# To remove the leading zeros from the date (as required by the puzzle) on Windows, use a pound sign between the % and the letter code.
54+
# EUDate = datetime.strftime(USDate,'%#d/%#m/%Y')
4655

4756
print(EUDate)

0 commit comments

Comments
 (0)