How to check the current date

Hello everyone I would like to know how to check if the current date is the right one or not
here is a beginning of code that I made but it does not work

#include <NTPClient.h>
// change next line to use with another board/shield
#include <ESP8266WiFi.h>
//#include <WiFi.h> // for WiFi shield
//#include <WiFi101.h> // for WiFi 101 shield or MKR1000
#include <WiFiUdp.h>

const char *ssid     = "<SSID>";
const char *password = "<PASSWORD>";

String newDate;
String oldDate;

// Week Days
String weekDays[7] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

WiFiUDP ntpUDP;

// By default 'pool.ntp.org' is used with 60 seconds update interval and
// no offset
NTPClient timeClient(ntpUDP);

// You can specify the time server pool and the offset, (in seconds)
// additionally you can specify the update interval (in milliseconds).
// NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 3600, 60000);

void setup(){
  Serial.begin(115200);
  WiFi.begin(ssid, password);

  while ( WiFi.status() != WL_CONNECTED ) {
    delay ( 500 );
    Serial.print ( "." );
  }

  timeClient.begin();
  
  newDate = weekDays[timeClient.getDay()];
}

void loop() {
  timeClient.update();
  if(newDate != olDtate){
  	oldDate = newDate;
    Serial.println('UPDATE DATE');
  }
  delay(1000);
}

Your topic was MOVED to its current forum category as it is more appropriate than the original as it has nothing whatsoever to do with Installation and Troubleshooting of the IDE

Please clarify what 's mean "does not work"?
Do you receive "Update date!" message at start?

Maybe that's the problem:

oldDate and olDtate - see the difference

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.