How to add a timer for an action to occur?

Dear gentlemen from the Arduino forum I have a question that I hope you can answer.
Let’s suppose I execute a code, for example:

if (conn.connect(server_addr, 3306, user, password)) {
// do something
}

I want to add a “timer” that works in this way:

You have 20 seconds to do this: {
if (conn.connect(server_addr, 3306, user, password)) {
// do something
}
}

if after 20 seconds you don’t do it, do something else.

Can I do that on arduino?

Best regards,
Sebastian

The millis() function is suited for what you want to do. When you wish to start the timer, record the value of millis() in a variable (start time). Then monitor millis() and when millis() is equal to or greater than your recorded start time plus the required interval (20 sec) the time is up.

Non blocking timing
how to do timing

Thanks for your help mister. Thanks a lot!