move a calender into a variable.

Hi all,

I am making a project of digital clock and calender using ARDUINO UNO. i want to add some task to it and alarm also. there will be no external inputs for alarm i am doing it in program only.

my question is how can i store calender into a single variable?
Like i print on lcd or serial port using…

Serial.print(tm.Day);
Serial.print(tm.Month);
Serial.print(tm.Year);

I am using Time.h library…n code is working fine. but i want to store all thing into a single variable…like if i store DAY,MONTH and YEAR into ‘c’…and i use Serial.print(c)…it should display whole calender.

Thnaks in advance if anyone can suggest.

struct{
  byte Day;
  byte Month;
  int Year;
} cal;

void setup(){
  Serial.begin(115200);
  cal.Day = 26;
  cal.Month = 11;
  cal.Year = 2014;
  Serial.println(cal.Day);
  Serial.println(cal.Month);
  Serial.println(cal.Year);
}//setup()

void loop(){}//loop()

use a time_t epoch value which is the best way to track time. a time_t value contains everything in a single integer variable. time_t values is how unix tracks time and is what is used by the time library as well so there are functions to translate back and forth between human readable form "struct tm" and "time_t".

--- bill

You could use an unsigned long:

unsigned long date;
date = (tm.Day*1000000UL) + (tm.Month*10000) + tm.Year;

Then you can print the date as a 7 or 8 digit number: 27112014