Calculate Weekday with your RTC

Script wrote in Javascript
© Adriano Petrucci





More info at: timeanddate.com

Calculation info:
Constants: Sun=0, Mon=1, Tue=2, Wed=3, Thu=4, Fri=5, Sat=6
Constants: (for step 4) 19xx=3, 20xx=2, 21xx=0, 22xx=5
                // More info at: https://www.timeanddate.com/date/doomsday-weekday.html
                // Arduino code
                int getWeekDay(int day, int month, int year)
                {
                  bool leapYear = ( (year%4)==0 && ( (year%100)!=0 || (year%400)==0 ) );
                  int val1 = (int)((year % 100) / 12);  // year / 12
                  int val2 = (year % 100) % 12;         // year % 12
                  int val3 = val2 % 4;                  // val2 % 4
                  int val4 = (year < 2000)?3:2;         // anchor/const
                  int val5 = val1+val2+val3+val4;       // sum
                  int val6 = val5 % 7;                  // convert to weekday
                  // Find doomday:
                  int doomsday = month;
                  if(month == 1) doomsday = (leapYear ? 4 : 3);
                  else if(month == 2) doomsday = (leapYear ? 29 : 28);
                  if((month % 2) != 0) doomsday = (month + 4 > 12) ? month - 4 : month + 4;
                  int val7 = day - doomsday;            // diff between day and doomsday
                  
                  return (val6 + val7 + 70) % 7;        // +70 to have a positive number
                }
              
Other tools:
ILI9341 Display Calculate Weekday