I'm not sure about this. The U.S. spent 18 years in Afghanistan. It still has troops in Iraq, but were there officially for 11 years while still doing combat missions into 2021.
The purpose of the military--the way it is structured, trained, and equipped--is to win battles and destroy armies. The U.S. military is, by far, the most powerful force to accomplish that purpose in human history. At this point, the U.S. can accomplish that objective anywhere in the world in a year, tops, I'd imagine, excluding China, maybe, given their numbers.
What the military is not very good at, though, is nation building or fighting an insurgency. That has nothing to do with the military qua military but everything to do with Western values. Past militaries not tied to the Western tradition were good at putting down insurgencies--the Mongols and the Romans. But the U.S. won't use their tactics (which I think a good thing)so, no matter how strong or smart our military, we will never be very good at that.
I think we need to internalize this lesson and be much more careful about where we deploy troops and, as has been repeated ad naseum during my lifetime, figure out what winning looks like before sending troops, and clearly defining objective requirements that bring troops home.