Python program to check whether a date is valid or not; Through this tutorial, i am going to show you how to check whether a given date is valid or not in python program.
Python Program to Check the Given Date is valid or not
- Write Python Program to Check the Given Date is valid or not
Write Python Program to Check the Given Date is valid or not
date=input("Enter the date in dd/mm/yy format: ") dd,mm,yy=date.split('/') dd=int(dd) mm=int(mm) yy=int(yy) if(mm==1 or mm==3 or mm==5 or mm==7 or mm==8 or mm==10 or mm==12): max1=31 elif(mm==4 or mm==6 or mm==9 or mm==11): max1=30 elif(yy%4==0 and yy%100!=0 or yy%400==0): max1=29 else: max1=28 if(mm<1 or mm>12): print("Date is invalid.") elif(dd<1 or dd>max1): print("Date is invalid.") elif(dd==max1 and mm!=12): dd=1 mm=mm+1 print("The incremented date is: ",dd,mm,yy) elif(dd==31 and mm==12): dd=1 mm=1 yy=yy+1 print("The incremented date is: ",dd,mm,yy) else: dd=dd+1 print("The incremented date is: ",dd,mm,yy)
Output
Enter the date in dd/mm/yy format: 25/04/2020 The incremented date is: 26 4 2020
Recommended Python Tutorials
Recommended:-Python Program to Reverse Numbers
Recommended:-Python Program to Find Largest of n Numbers
Recommended:-Python Program to Find Power of Number
Recommended:-Python Program to Print Prime Number From 1 to N
Recommended:-Python Program to Find Square Root of Number
Recommended:-Python Program to Find Cube of Number
Recommended:-Python Palindrome Program
Recommended:-Python Program to Count Set Bits in a Number
Recommended:-Python Program for BMI Calculation
Recommended:-Python Program to Find Out Absolute Value
Recommended:-Python Random Number Generator Code
Recommended:-Python program for Zip, Zap and Zoom game
Recommended:-Python Program to Swap Two Numbers
Recommended:-Python Program to Find n-th term of Fibonacci Series
Recommended:-Python Program For Calculator
Recommended:-Python Program to Find Strong Number
Recommended:-Python Program to Convert cm to Feet and Inches
Recommended:-How to Reverse a List in Python
Recommended:-Python Program to Convert Celsius to Fahrenheit
Recommended:-Python Program to Find Standard Deviation
Recommended:-Python Program to Check Perfect Number