Rtc week day

How do I get the day of the week by the RTC to compare it with the time input?

I’m producing an application and I need to make this comparison to create an event when the two are the same.

Here’s a fragment of my code. You’ll need to include timelib.h, and possibly some other things:

        time_t currentDT = now();
        if (alertSchedule->getStartMode() != TimeInputParam::TIME_UNDEFINED)
        {
            if (alertSchedule->isWeekdaySelected(weekday(currentDT) + 7 - 1)) //is scheduled for today (adjustment needed to sync the two day-of-week numbering systems)
            {
.....
            }
        }

alertSchedule is set elsewhere during the write event:

TimeInputParam* alertSchedule = NULL; //global
BLYNK_WRITE(VPIN_TIME_INPUT_3_VPIN)
{
    if (alertSchedule != NULL)
        delete alertSchedule;
    alertSchedule = new TimeInputParam(param);
}

I hope that helps.

How do I remove the blynk RTC’s day of the week information? because the comparison I can make with my problem is how to extract the information of the day of the week from the RTC

just use weekday(), for more details, see here:

https://playground.arduino.cc/Code/Time

just be aware, that the blynk widget uses 1 for monday, and the arduino implementation uses 1 for sunday, so, you have to write a small logic for “level shifting”. but that is really easy :wink:

1 Like

Doing a smash and grab from Costas EziScheduler it could look like this:

int dayadjustment = -1;
if (weekday() == 1){
  dayadjustment = 6; // needed for Sunday Time library is day 1 and Blynk is day 7
}

if (t.isWeekdaySelected((weekday() + dayadjustment))) { 
		// code here
}

But I have never understood who would start the week on a Sunday :face_with_raised_eyebrow:

1 Like

well, who drives on the opposite side, of course :slight_smile: the brits. probably, they thought it is best to begin the week with a break :wink:

4 Likes