During the night you can safely hold your urine in for up to 10 hours and it's likely safe to do so for that long in the daytime as well if needed.
But when you're awake and you feel the urge to pee you should hold it no longer an hour or 2 because you risk getting bladder infections and UTI Urinary Tract infections as well as developing kidney disease.
Always get up and go to the restroom to relieve yourself of the urine as soon as possible and avoid holding in your urine any longer than you really need too.