Created
July 24, 2020 16:01
-
-
Save muthu1809/64a3b894cd12c736bfafd0732e82b894 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
datePattern = re.compile(r'([0-3][0-9])/([0-1][0-2])/((\d){4})') | |
dateFound = datePattern.search('My birthdate is 31/09/2000') | |
if not dateFound is None: | |
print(dateFound.groups()) | |
day = dateFound.group(1) | |
month = dateFound.group(2).strip("0") # strip என்ன செய்யும் என்று கொஞ்சம் சிந்தியுங்களேன். | |
year = dateFound.group(3) | |
print(day, month, year) | |
if int(month) in [1,3,5,7,8,10,12]: | |
if int(day)>31: | |
print("Invalid Date, Date can't be greater than 31") | |
elif int(month) in [4,6,9,11]: | |
if int(day)>30: | |
print("Invalid Date, Date can't be greater than 30") | |
else: | |
if int(day)>29: | |
print("Invalid Date, Date can't be greater than 29") | |
elif int(day)==29: | |
y = int(year) | |
if not (((y%4)==0) and ((y%100)==0) and ((y%400)==0)): | |
print("Invalid Date, Date can't be greater than 28") | |
else: | |
print("Invalid Date") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment