The S&P 500 hit a nine-month high on Thursday, fueled by strong U.S. economic data and increased hopes for a deal on a Greek bailout next week.

The benchmark index posted its strongest percentage gain in two weeks, bouncing back from several sessions of back-and-forth action.

Sectors sensitive to economic growth paced the market, with technology, materials and financials leading on a day when all 10 S&P sectors finished higher.

Even with Thursday's gains, equity indexes remained in tight ranges, with the 1,360 barrier that investors cited for the S&P 500 as an impediment to more gains.

We really need to churn through this area. We've been here before, we've failed here before, said Stephen Massocca, managing director at Wedbush Morgan in San Francisco.

The Dow Jones industrial average <.DJI> gained 123.21 points, or 0.96 percent, to 12,904.16. The Standard & Poor's 500 Index <.SPX> climbed 14.82 points, or 1.10 percent, to 1,358.05. The Nasdaq Composite Index <.IXIC> rose 44.02 points, or 1.51 percent, to 2,959.85.

Bank shares rose, brushing off a warning from Moody's about possible downgrades to credit ratings of 17 global and 114 European financial institutions.

Greece expects to get approval on Monday from euro zone finance ministers to begin a debt swap with private bondholders, a spokesman for the Greek government said, moving closer to averting a disorderly default. That sparked the day's rally, particularly in financial shares.

Among the ratings threatened were those of Goldman Sachs , up 1.4 percent at $114.74, and Bank of America , up 4 percent at $8.09. The KBW bank index <.BKX> rose 2.2 percent.

Shares of Microsoft hit a 52-week high of $31.55, garnering buying interest on heavy volume. The stock was the most actively traded on the Nasdaq Stock Exchange, closing at $31.29, up 4 percent.

The CBOE Volatility index <.VIX> dropped 8.7 percent, its biggest decline since December 9.

U.S. labor, manufacturing and housing data suggested sustained momentum in those key economic sectors and hinted the recovery continues at a steady pace.

We continue to get certain economic indicators coming in at a 4 and 5 year high, or low, depending on the indicator. It's pretty clear something is going on out there and the market is reacting to that, said Massocca.

Apple shares, which largely dictated the direction of Wednesday's stock market, finished up 0.9 percent at $502.21. Trading in Apple topped 33 million shares, above its 19.5 million average in the past 10 days.

According to a Chinese newspaper website, some cities in China have asked retailers to take Apple iPad tablets off shelves in connection with a legal battle between a Chinese technology firm and Apple over trademark issues.

The S&P closed at its highest level since May 2 while the Nasdaq ended at its highest since December 2000 and the Dow finished at its highest level since May 2008.

Volume was solid with about 7.33 billion shares traded on the New York Stock Exchange, NYSE Amex and Nasdaq, slightly above the daily average of 7 billion.

Advancing stocks outnumbered declining ones on the NYSE by 2,269 to 752, while on the Nasdaq, advancers beat decliners 1,927 to 587.

(Reporting By Chuck Mikolajczak; Editing by Kenneth Barry)