It is not possible to cancel delay(). For that reason, delay() is rarely used. Instead, people use other means of timing events, described in this tutorial on the Blink Without Delay program example.
I moved your topic to an appropriate forum category @kawal14feb.
In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.
sounds like you want one button to start a timer and have a 2nd button that resets the timer before it expires
see how instead of using delay, millis() is used to see when the desired amount of time, msecPeriod has elapsed since the time when the button was pressed, msec0.
because millis() returns immediately, other things can be done while the timer code checks millis() each iteration of loop()
see how the timer is enabled by setting msecPeriod. the timer can easily be disabled by setting msecPeriod to zero because it's one of the 2 conditions (&&) to check the timer
const int sPin1 = 8;
const int sPin2 = 9;
#define OFF LOW
#define ON HIGH
unsigned long msecPeriod;
unsigned long msec0;
void loop ()
{
unsigned long msec = millis ();
// check timer
if (msecPeriod && msec - msec0 >= msecPeriod) {
msecPeriod = 0; // disable timer
digitalWrite (LED_BUILTIN, OFF);
}
// check for start
if (LOW == digitalRead (sPin2)) {
msec0 = msec;
msecPeriod = 5000;
digitalWrite (LED_BUILTIN, ON);
}
// check to reset
if (LOW == digitalRead (sPin1)) {
msecPeriod = 0; // disable timer
digitalWrite (LED_BUILTIN, OFF);
}
}
void setup ()
{
Serial.begin (9600);
pinMode (sPin1, INPUT);
pinMode (sPin2, INPUT);
pinMode (LED_BUILTIN, OUTPUT);
digitalWrite (LED_BUILTIN, OFF);
}