Given a date, check if it is valid or not. It may be assumed that the given date is in range from 01/01/1800 to 31/12/9999.
Input : d = 10, m = 12, y = 2000 Output : Yes The given date 10/12/2000 is valid Input : d = 30, m = 2, y = 2000 Output : No The given date 30/2/2000 is invalid. The February month cannot have 30 as day.
The idea is simple. We need to handle following things.
1) y, m and d are in allowed range.
2) Days in February are in allowed range and leap year is handled.
3) Days in 30 day months are handled.
Below is C++/Python implementation to check if a given year is valid or not.
This article is contributed by RAHUL NITKKR. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Check if the given chessboard is valid or not
- Check if the given Prufer sequence is valid or not
- Check whether Quadrilateral is valid or not if angles are given
- Check if the given Binary Expressions are valid
- Check whether triangle is valid or not if sides are given
- Check if a + b = c is valid after removing all zeroes from a, b and c
- Check whether the triangle is valid or not if angles are given
- Check if the number is valid when flipped upside down
- Check whether right angled triangle is valid or not for large sides
- Program to generate all possible valid IP addresses from given string | Set 2
- C++ Program to print current Day, Date and Time
- Python program to find day of the week for a given date
- Program to Convert Milliseconds to a Date Format in Java
- Date after adding given number of days to the given date
- Program to display Astrological sign or Zodiac sign for given date of birth
Improved By : nitin mittal