C Program To Display Day of a Date
Learn how to display day of a date in C Programming language. This C code makes use of Switch case to find the day of the week associated to a date. This program does not use any library functions nor any user defined functions.
Must Read: C Program To Find System Date and Time
C Program To Display Day From A Date using Switch Case
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | #include<stdio.h> #include<stdlib.h> int main() { int dd, mm, yy; int count, n; int day, month, year; printf("\nInput the Current Date in Numbers\n"); printf("Date:\t"); scanf("%d", &dd); printf("Month:\t"); scanf("%d", &mm); printf("Year:\t"); scanf("%d", &yy); if(dd > 31 || mm > 12) { printf("\nPlease Enter the Correct Date\n"); exit(0); } year = yy - 1900; year = year / 4; year = year + yy -1900; switch(mm) { case 1: month = 1; break; case 2: month = 4; break; case 3: month = 4; break; case 4: month = 0; break; case 5: month = 2; break; case 6: month = 5; break; case 7: month = 0; break; case 8: month = 3; break; case 9: month = 6; break; case 10: month = 1; break; case 11: month = 4; break; case 12: month = 12; break; } year = year + month; year = year + dd; day = year % 7; switch(day) { case 0: printf("\nDay:\tSaturday\n"); break; case 1: printf("\nDay:\tSunday\n"); break; case 2: printf("\nDay:\tMonday\n"); break; case 3: printf("\nDay:\tTuesday\n"); break; case 4: printf("\nDay:\tWednesday\n"); break; case 5: printf("\nDay:\tThursday\n"); break; case 6: printf("\nDay:\tFriday\n"); break; } return 0; } |
Must Read: C Program To Check if a Number is a Strong Number or Not
Output

If you have any doubt or compilation error in this C Code to Find Day of the Week on a given Date, let us know about it in the comment section.
What a fantastic piece of code. This is just so easy to find the day of the week without using any functions.
I have not seen such an easy algorithm for finding the day of a given date in C programming. It is so easy.
I have not ever seen such an easy code finding the day of a given date in C programming. It is such an easy yet complex code.
please explain the code or else explain me logic and math I am not getting
Can you explain wt is case 1: month =1; in the same way of 12 month values??
can i get a flow chart for this
Can you please paste your code here and also let us know about the OS that you’re using.
I didn’t get the logic behind using 1900
Hi, Nice code. There is no 29th feb in 2018 (since this is not a leap year). But this is displaying as Thursday
What is Logic behind these no’s which are assigned to months in switch case. Please Do Share the logic behind it
please briefly explain about an algorithm
try (27-12-1997) it shows Friday but it was Saturday
case 1: month=1 means they took mean value for all months. JFM AMJ JAS OND = 144 025 036 1412