Not as long as you might think
It depends on the assumptions you're willing to make.
With the world population growing at a vigorous 2% per year, there would be a trillion people alive in around the year 2260. The fastest human population has ever grown in recent history was 2.2% per year in the early sixties. This type of scenario would correspond to a strongly pronatalist policy by the powers-that-be, perhaps going as far as banning birth control and mandating early marriage.
With the world population growing at a more moderate 1% per year, there would be a trillion people alive in around the year 2500. This rate is about where we are currently. As the population ages and becomes more urban, most demographers think the population growth rate will slow even further. From an overall perspective, many industrial democracies in fact have strongly negative growth rates if you exclude immigration. However, there are fast-growing subpopulations with strong pronatalist proclivities that will become dominant if current growth rates are maintained.
With the world population growing at a glacial 0.1% per year, you wouldn't reach a trillion until almost the year 7000. This would be a slow growth scenario, and the one that gives mankind the most time to adapt. Perhaps a society where aging has been cured and very few people choose to have children at a particular given point might look like this.
The energy and food requirements of such a host would be far beyond our current technologies, and might require extensive industrialization and agriculturalization of space.
Imagine that view: a billion miles of space-farms, their bright green glittering against the dark sky, surrounding Earth like a gigantic set of Saturn-like rings. The plants within are made of organic material harvested from Titan, and are powered by the abundant 24h/day inflow of solar energy. A dense mesh of thousands of massive space elevators carry food to Earth and 'fertilizer' from Earth.
If you're not limiting yourself to Earth, but allow for space farming habitats, space industries and even extraterrestrial colonies, the cosmic resources available in the solar system can easily support a trillion people. To give a simple example, the energy output from the sun is so enormous, that if all of it were captured, each one of the trillion people would have 100 times as much energy as all of today's humanity combined. We have all the organic volatiles we could ever need on Titan, oceans of it, metals in the asteroid belt, quadrillions upon quadrillions of tons. Our solar system's resources are literally on cosmic scale.
Can we house everyone on Earth?
A trillion people sounds like a lot. Nonetheless, humans are pretty small and Earth is pretty large. Plus its nice to have the air already here, not leaking into space, a magnetosphere, comfortable 1g gravitation ready made, all that good stuff. So Earth is pretty damn convenient. Let's see how much space they would take. If we use the density of a place like Mumbai, India, (30,000 people/sq.km) and extrapolate from there, you could fit a trillion people in an arcology covering about 23% of Earth's land area. That's about the area of Earth's deserts. So with a trillion people on it most of Earth could be a lush unspoiled garden... Moreover, since such an arcology whould presumably be multilevel, each individual could have a vastly larger living area than a current resident of Mumbai.
So we can definitely fit a trillion people on Earth, but Earth alone probably does not have the energy resources to feed them and meet all of their future needs.