When I came back from The UK last year, my pcr test was dated and timed only 75 minutes before my flight departure time; fortunately, it left on time.
The problem is that not all the test companies do same day result. So, you might have to travel for the test if you want a decent time lapse between result and flight.
Good luck with that.