BENTONVILLE, ARK. — Shares of Walmart Inc. on the New York Stock Exchange gained as much as 5% in mid-day trading Aug. 15, after the retailer posted strong second-quarter results and raised its full-year earnings forecast.

Walmart U.S. comparable sales, excluding fuel, increased 2.8% in the quarter and more than 7% on a two-year basis, representing the segment’s strongest growth in more than a decade, said Brett M. Biggs, chief financial officer of Walmart.

“Comp sales growth reflects strength in grocery, including strong growth in private brands,” Mr. Biggs said. “We’ve been pleased with the consistently strong performance in food and consumables as the category had a mid-single digit comp increase in the quarter and the best two-year stacked comp in nearly 10 years. Comp ticket was affected by slight deflation in food this quarter while consumables’ inflation increased modestly.”

Consolidated net income attributable to Walmart in the second quarter ended July 31 was $3,610 million, or $1.27 per share on the common stock, which compared with a loss of $861 million in the year-ago period.

Reported earnings in the year-ago quarter were impacted by a charge related to the sale of a majority stake in Walmart Brazil, an adjustment to the provisional tax amount related to tax reform and an unrealized loss on the company’s equity investment in

Revenues totaled $130,377 million, up 1.8% from $128,028 million. On a constant currency basis, revenues were up 2.9%.

“Reflecting year-to-date results and continued momentum in the business, we are raising FY20 guidance for Walmart U.S. comp sales, consolidated operating income and adjusted e.p.s.,” Mr. Biggs said. “Both Walmart U.S. and Sam’s Club delivered strong sales growth, and Walmart International’s overall sales were solid despite some softness in certain markets, including the U.K. and Canada.

“We’re slightly adjusting the net sales growth guidance from at least 3% in constant currency for fiscal 2020 to around 3%. While we expect continued strong sales in the U.S., we are lowering our expectations for sales growth in International to a range of between 3% and 4% due primarily to softness in the U.K. and Canada. We also expect currency to be a continued headwind in Q3.

“Based on current exchange rates, we estimate net sales will be negatively affected by about $500 million in the third quarter, which is higher than anticipated at the beginning of the year.”

He added, “For Walmart U.S. comp sales, strong first-half results lead us to increase our full-year expectations, excluding fuel, to the upper end of the original guidance of up 2.5% to 3%.”

Walmart U.S. e-commerce sales increased 37% in the quarter, fueled by strong growth in online grocery. The company has surpassed 1,100 grocery delivery locations and has more than 2,700 pickup locations at its U.S. stores. The company’s next-day delivery service now covers about 75% of the U.S. population.

“As we scaled grocery pickup in the U.S., it unlocked new capabilities like grocery delivery,” said C. Douglas McMillon, president and chief executive officer of Walmart. “Customers love these services, and we’re rapidly expanding them to new locations and testing new options such as unlimited grocery delivery for a fee.”

Walmart in-home grocery deliveryWalmart is launching in-home delivery to nearly one million shoppers in three U.S. cities, he said.

“Starting in the fall of this year, a group of highly-trained Walmart associates will begin delivering groceries directly into the homes of customers — maybe in a garage, or in the refrigerator,” Mr. McMillon said.

During the quarter, Suresh Kumar was named to the newly created role of chief technology officer and chief development officer. The company also recently announced the hiring of Janey Whiteside as its first-ever chief customer officer.

“A natural progression to these and other changes we’ve made is to streamline other parts of the business in support of our omnichannel focus,” Mr. McMillon said. “The organizational changes we made in the U.S. during the quarter in areas like supply chain and finance are a critical step in our journey and will build upon our strong foundation. We’ve maintained some separation in merchandising for stores and e-commerce to keep the focus on our goals and enable speed.”

Year to date, consolidated net income attributable to Walmart totaled $7,452 million, equal to $2.60 per share on the common stock, which compared with $1,273 million, or 43c, in the same period of the prior year. Revenues for the six-month period were $254,302 million, up 1.4% from $250,718 million.

“Customers are responding to the improvements we’re making, the productivity loop is working, and we’re gaining market share,” Mr. McMillon said. “We have good momentum, and I look forward to what we’ll accomplish during the back-half of the year.”