Compare date

Hi all. I stuck in compare date(use DS3231+ Mega) on my project Ex. when mega opened on 26-05-2016 and i write some data to EEPROM and open again if it not 26 or not same date (i want Mega to delete all EEPROM stored) i wonder how to code that

i wonder how to code that

I wonder what your current code looks like...

I wonder what your current code looks like…

I have no idea what i’m doing , I think i will store date in to EEPROM and EEPROM can store only number right?

#include <Wire.h>
#include <DS3231.h>

#include <EEPROM.h>
DS3231 clock;
RTCDateTime dt;

char settime[1];
void setup()

  // Initialize DS3231
  Serial.println("Initialize DS3231");;

  // Set sketch compiling time
  clock.setDateTime(__DATE__, __TIME__);

  // Set from UNIX timestamp
  // clock.setDateTime(1397408400);

  // Manual (YYYY, MM, DD, HH, II, SS
  // clock.setDateTime(2014, 4, 13, 19, 21, 00);
  char  *settime1=clock.dateFormat("d ", dt);


void loop()
  dt = clock.getDateTime();

  Serial.print("Long number format:          ");
  Serial.println(clock.dateFormat("d-m-Y ", dt));

  Serial.print("Long format with month name: ");
  Serial.println(clock.dateFormat("d F Y H:i:s",  dt));

  Serial.print("Short format witch 12h mode: ");
  Serial.println(clock.dateFormat("jS M y, h:ia", dt));

  Serial.print("Today is:                    ");
  Serial.print(clock.dateFormat("l, z", dt));
  Serial.println(" days of the year.");

  Serial.print("Actual month has:            ");
  Serial.print(clock.dateFormat("t", dt));
  Serial.println(" days.");

  Serial.print("Unixtime:                    ");
  Serial.println(clock.dateFormat("U", dt));



I have no idea what i'm doing

I can see that.

char settime[1];

A global array that can hold one element.

  char  *settime1=clock.dateFormat("d ", dt);

A local variable with the same name and a different type. NOT a good idea.

And, the local variable immediately goes out of scope, so it was pointless to define it, or call the function.

Why do you want to store the date/time in EEPROM? You can always get the current date/time from the clock.

EEPROM can store only number right?

Yes, but why would that be a problem? Dates and times are numbers.

oh i missed type it should be

char settime1[1];
 char  *settime1=clock.dateFormat("d ", dt);

in this case some error show clock.dateFormat("d ", dt) is a char

Actually i made project count number when tap card (about 10 card or maybe more, 1 card /person--Mega+sd card +DS3231+rc522 ) and when each person tap they're card and count how many time they're tap each person card and store in EEPROM(for each person ) Stored in EEPROM because when the power down abd back again it will count from latest stage ,So and i have button for clear EEPROM when it's pushed ,clear because i want data for each day. And SO, if i dont remmember to push that button ,when tap card it'll count continute for latest number that stored on EEPROM ,I want each data for each day not continut count from last day .That's why i want to compare day.

Sorry for my English i hope you understand ,So if you dont understand with my project i'll send video clip to you .

in this case some error show clock.dateFormat("d ", dt) is a char

What error? We do not deal with "well, I think I remember the error message saying something about some line of the code returning something that I was trying to store in a variable of some other type...". We deal with EXACT error messages.

That's why i want to compare day.

You don't need to. You check the day. When the day this time is not the day last time (doesn't matter what either are), clear the EEPROM. All that tat requires is that you have a global or static variable called lastDay that you assign a value to after checking the current day read from the clock. I don't know what methods you have to get data from your clock, but suppose that there was one called day(), and the class instance is called clock.

   int currDay = clock.getDay();
   if(currDay != lastDay)
      // The day changed. Clear the EEPROM
   lastDay = currDay;

At the end of the month, currDay will become 1, while lastDay will be 28, 29, 30, or 31, depending on the month and year. But, the exact value of currDay and lastDay doesn't matter.