In this tutorial, we will write a C program to check date is valid or not. Given the date, month and year, the program finds whether it is valid or not. Although before jumping to the main program, you should have knowledge of the following topics in C programming.
The valid Range for a date, month, and year is 1/1/1800 – 31/12/9999.
Explanation- What does the following program check for:
- For Date: The date cannot be less than 1 and more than 31.
- For Month: Month cannot be less than 1 and more than 12
- For year: The maximum and minimum year is taken before the main program that is less than 1800 and more than 9999.
- Leap Year: Checks if the year is a leap year or not.
- If it is a leap year, the February month will have 29 days.
- If it is not a leap year, the February month will have 28 days.
- For 30 days month: The months April, June, September, and November cannot have more than 30 days
C Program Date is Valid or Not
//take constant value for min and max year
#define max_yr 9999
#define min_yr 1800
/*function to check the leap year
if yes returns 1 else 0*/
int isleapYear(int y)
if ((y % 4 == 0) && (y % 100 != 0) && (y % 400 == 0))
//separate function to valid date or not
int isDateValid(int d, int m, int y)
if (y < min_yr || y > max_yr)
if (m < 1 || m > 12)
if (d < 1 || d > 31)
/*for february month
if leap year feb has 29 days else 28 days*/
if (m == 2)
if (d <= 29)
//for 30 days months (April, June, September and November)
if (m == 4 || m == 6 || m == 9 || m == 11)
if (d <= 30)
int main(int argc, char
int d, m, y;
printf("Enter date (DD/MM/YYYY format): ");
scanf("%d/%d/%d", &d, &m, &y);
if (isDateValid(d, m, y))
printf("Date is valid.");
printf("Date is not valid.");
Enter date (DD/MM/YYYY format): 13/06/1998
Date is valid.
In this tutorial, we will write a program to find a pairs of elements from an array such that for the input [a,b,c,d,e,f,g] we will …
String Pattern Programs in C
In this tutorial, we will write various C pattern programs for String. Before that, you may go through the following topics in C. for loop …
Java Program to Find pair of Integers in Array whose sum is given Number
In this tutorial, we will write a program to find a pair of elements from an array whose sum equals a given number in java …
Program to Print Diamond Alphabet Patterns in C
In this tutorial, we will learn to write a C program to print Diamond patterns using alphabets/characters. However, in this tutorial, we will create a …
Half Diamond Pattern in C using Alphabets
In this tutorial, we will learn and code the half diamond alphabet patterns in C programming language. However, in this tutorial, we will create a …
Half Pyramid of Alphabets in C
In this tutorial, we will learn and code alphabet patterns in C programming language specifically the Half pyramid of alphabets in C programming. However, in …