Danks had been on the disabled list since May 20 because of abnormal soreness in his left throwing shoulder. He last pitched for the White Sox on May 19. He made a rehab start in Triple-A on June 12 and again felt irregular soreness afterward. He's been rehabbing his shoulder for the last month and a half with a hope of still returning this season.
"It's tough obviously," Danks said on Tuesday. "This whole time this has been the absolute last resort. Going on 8-9 weeks now we haven't made improvements we hoped and we thought we would be making. You got to do what you got to do.
"We got to the point where we couldn't help to start thinking about next year and cut our losses this year and try to be ready by spring. These guys are playing well enough without me, getting (Francisco) Liriano certainly helps. I definitely think there's plenty here now that me being out is not going to kill this team. I'll be a cheerleader now for the next two, three months hopefully."
The White Sox are in first place in the AL Central. They recently added Liriano in a trade with the Minnesota Twins. Rookie Jose Quintana replaced Danks in the rotation in May and is 4-1 with a 2.80 ERA in 14 games, including 12 starts.
"It's disappointing for him, I know that," White Sox manager Robin Ventura said. "In the long run, you find out what it is. That's the biggest thing.
"To get him able and be ready to pitch at this level and be effective and do all the things he would feel confident going out there, time was getting a little short for that. With the way he was feeling, the timing of it, it's time to just go in and find out what it is and take care of it."
The surgery will be performed by team surgeons from Midwest Orthopedics at Rush University Surgery Center in Chicago.
Danks said on July 25 he had thought he had taken a step forward in his rehab, but the progress was short-lived, and he mentioned the possibility of surgery on Saturday.
Danks is 3-4 with a 5.70 ERA in nine starts this season.
Danks received a five-year, $65 million contract extension in the offseason.
In other rotation news, left-hander Chris Sale, who has been on a break from the team's rotation to rest his tired arm, will return to action on Aug. 7 against Kansas City, Ventura said.
Sale, 12-3 with a 2.61 ERA in his first full year of starting, initially was on track to return to the rotation this weekend against the Los Angeles Angels. But the team decided to give Sale more time between starts, and had the luxury of doing so after acquiring Liriano.
The left-hander last pitched on July 27, allowing five runs in 6 1/3 innings against the Rangers.
Ben Goessling contributed to this report.