You may only use your horn to avert imminent danger. The same rule applies to flashing your headlights.
The rule is article 28 of the RVV 1990: drivers may only give sound signals and light signals to avert imminent danger. Your horn is a sound signal. A quick flash of your headlights is a light signal.
So honking to greet someone, to say thanks or to hurry someone up is not allowed. Nor is honking because someone is in your way or makes a mistake, if there is no danger.
An example where it is allowed: a cyclist rides out of a driveway into the road without looking, right in front of your car. You brake and sound your horn to warn them.
The law makes no distinction between day and night, or between built-up areas and open roads. The rule is always the same: only to avert danger.
Watch out Your horn is a warning, not a solution. When danger threatens, brake or steer away first if you need to. And you may never cause danger or obstruct traffic yourself.