How to make Arduino display a specific time and date?

The program is supposed to display a specific date, for example: 1992-02-23 and specific time, for example: 4:45:12

I got the time part down and the code now looks like this:

#include <DateTime.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
void setup(){
 lcd.begin(16, 2);
 DateTime.sync(812868312);
}
void  loop(){     
 if(DateTime.available()) { 
   unsigned long prevtime = DateTime.now(); 
   while( prevtime == DateTime.now() )
     ;
   DateTime.available();
   digitalClockDisplay();
 } 
}

void printDigits(byte digits){
 lcd.print(":");
 if(digits < 10)
   lcd.print('0');
 lcd.print(digits,DEC);
}

void digitalClockDisplay(){
 lcd.home();
 // digital clock display of current time
 lcd.print(DateTime.Hour,DEC);  
 printDigits(DateTime.Minute);  
 printDigits(DateTime.Second);
}

But I'm not sure how to add a specific date.
Any suggestions of where to start?

acurate:
Any suggestions of where to start?

Yep. You could start by placing your code in a code block, (between code tags).

You really should have read the How to use this forum - please read post at the top of the index page and How to use this forum before posting.

ie Your code and any error messages should always be placed between code tags. Posting it inline as you have done makes it much harder to read or copy and paste for diagnosis.

They can also be added manually:-

[code]Paste your code here[/code]
It will appear in a block like this

It's still not too late to edit your post and do this. You'll make potential helpers much happier. :slight_smile:

To display a specific date and time, you have WAY too much code.

#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
void setup()
{
   lcd.begin(16, 2);
   lcd.print("1992-02-23 4:45:12");
}

void loop()
{
}

Hi

If you need it for printing different time and date from UNIX format, and not a fixed time and date, this could maybe be helpfull

// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 rtc;

char daysOfTheWeek[7][12] = {"Søndag", "Mandag", "Tirsdag", "Onsdag", "Torsdag", "Fredag", "Lørdag"};

void setup () {
  pinMode (A8,OUTPUT); // Power for RTC
  digitalWrite(A8,LOW); // Power for RTC
  pinMode (A9,OUTPUT); // Power for RTC
  digitalWrite(A9,HIGH); // Power for RTC
  Serial.begin(115200);
    if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1); //Halt
  }
}

void loop () {
    DateTime now = rtc.now();
 
    printDate(now,"A");
    Serial.println();
    printDate(now,"L");
    Serial.println();
    printDate(now,"M");
    Serial.println();
    printDate(now,"S");
    Serial.println();
    printDate(now,0);
    Serial.println();
    
    delay(10000);
}
void printDate(DateTime TimeBuffer, const char *type){;
// unixtime, type All Long Medium Short

  if(type == "A"){
    Serial.print(daysOfTheWeek[TimeBuffer.dayOfTheWeek()]);
    Serial.print(" ");
  }
    if(type == "A" or type == "L" or type == "M" or type == "S"){

      Serial.print(TimeBuffer.year());
      Serial.print('-');
      Serial.print(formatTimeDigits(TimeBuffer.month()));
      Serial.print('-');
      Serial.print(formatTimeDigits(TimeBuffer.day()));
    }
    if(type == "A" or type == "L" or type == "M"){
      Serial.print(" ");
      Serial.print(formatTimeDigits(TimeBuffer.hour()));
      Serial.print(':');
      Serial.print(formatTimeDigits(TimeBuffer.minute()));

     }
    if(type == "A" or type == "L"){
      Serial.print(':');
      Serial.print(formatTimeDigits(TimeBuffer.second()));
    }
//      Serial.print("Format NOT selected");

} //printDate End

String formatTimeDigits(int num){
  char strOut[3];
  strOut[0] = '0' + (num / 10);
  strOut[1] = '0' + (num % 10);
  strOut[2] = '\0';
  return strOut;
} // formatTimeDigits
#include <DateTime.h>

From Arduino Playground - HomePage

This library has been superseded by a newer version. Follow this link Arduino Playground - HomePage

But I'm not sure how to add a specific date.
Any suggestions of where to start?

See the example programs in the Time library.