How to use button

Hi!
I am writing a program for displaying the time on lcd. I want to add the command line of the button so I can next or back without the delay function.
For example, I want to show the hour first, then press the button to display the next day.

Hope you help me write the code.
Thank you!

OP’s schematic.

Use CTRL T to format your code.
Attach your ‘complete’ sketch between code tags, use the </> icon in the posting menu.
[code]Paste your sketch here[/code]

No, we help fix your code. We don't write it for you. If you want somebody to write the code for you, go to the Gigs and Collaboration forum and hire somebody.

At a minimum you start by assigning names to the button pins:

const byte Button1DIPin = 9;
const byte Button2DIPin = 8;

Then in setup() you set the pin mode to INPUT. NOTE: You could eliminate the two pull-down resistors by using INPUT_PULLUP and connecting the buttons between the pins and Ground.

  pinMode(Button1DIPin, INPUT);
  pinMode(Button2DIPin, INPUT);

In the loop() function you will want to detect when each button is pressed. To detect the CHANGE from not-pressed to pressed you need a variable to store the previous state. To do the debounce you need to know how long it's been since a button was last pressed. You can use the same timer for both buttons.

const unsigned long DebounceTime = 30;
void loop()
{
  unsigned long currentTime = millis();
  static unsigned long buttonStateChangeTime = 0;


  static boolean button1AlreadyPressed = false;
  boolean button1Pressed = digitalRead(Button1DIPin) == HIGH;  // Active HIGH

  static boolean button2AlreadyPressed = false;
  boolean button2Pressed = digitalRead(Button2DIPin) == HIGH;  // Active HIGH


  // Check for button1 change and do debounce
  if (button1Pressed != button1AlreadyPressed &&
      currentTime -  buttonStateChangeTime > DebounceTime)
  {
    // Button state has changed
    buttonStateChangeTime = currentTime;
    button1AlreadyPressed = button1Pressed;


    if (button1Pressed)
    {
      // Button1 was just pressed
      // PUT THE CODE FOR A BUTTON1 PRESS HERE
    }
  }

  // Check for button2 change and do debounce
  if (button2Pressed != button2AlreadyPressed &&
      currentTime -  buttonStateChangeTime > DebounceTime)
  {
    // Button state has changed
    buttonStateChangeTime = currentTime;
    button2AlreadyPressed = button2Pressed;

    if (button2Pressed)
    {
      // Button1 was just pressed
      // PUT THE CODE FOR A BUTTON2 PRESS HERE
    }
  }
}

Thank you so much, johnwasser.