C++ program to get week day from given date
Given a date, and we have to find weekday like Sunday, Monday etc from given date.
Here, we are using given formula to get the weekday number from 0 to 6 and behalf on this weekday number, we are able to get the weekday from declared array (we have to declare an array of strings with weekday names).
int rst =
dd
+ ((153 * (mm + 12 * ((14 - mm) / 12) - 3) + 2) / 5)
+ (365 * (yy + 4800 - ((14 - mm) / 12)))
+ ((yy + 4800 - ((14 - mm) / 12)) / 4)
- ((yy + 4800 - ((14 - mm) / 12)) / 100)
+ ((yy + 4800 - ((14 - mm) / 12)) / 400)
- 32045;
Consider the program:
Output
need an explanation for this answer? contact us directly to get an explanation for this answer