Giancarlo Stanton of the Yankees scores a run in the...

Giancarlo Stanton of the Yankees scores a run in the fourth inning against Atlanta at Yankee Stadium on Saturday. Credit: Jim McIsaac

On the day the Yankees put Giancarlo Stanton on the injured list, they also addressed an unrelated need that had been percolating for weeks.

Shortly after announcing Stanton’s left hamstring strain, which the designated hitter expects to sideline him for about four weeks, the Yankees announced on Sunday that they had traded for A’s utilityman J.D. Davis, a Met from 2019-22.

Though primarily a third baseman in his career, Davis, 31, also can play first base (as well as a little outfield). Both of those infield positions were areas the Yankees were looking to bolster.

And that was true even before Anthony Rizzo, who had been struggling at the plate and in the field, recently was lost for at least two months with a right forearm fracture.

The Yankees’ response to that was to elevate Ben Rice after a minimum number of games with Triple-A Scranton/Wilkes-Barre, though the 25-year-old prospect has never been viewed as the long-term solution at first — at least not for this season. It also is a position the catcher only recently began playing.

Scouts, though mostly liking Rice’s potential as a hitter, have not been as complimentary about his defense.

After Sunday’s game, Aaron Boone said the idea is for the righthanded-hitting Davis to platoon at first with the lefthanded-swinging Rice.

The Yankees acquired Davis — hitting .236 with four homers, four doubles and a .670 OPS in 39 games with Oakland — for minor-league infielder Jordan Groshans. The Yankees also received cash considerations.

Stanton left the Yankees’ 8-3 win over Atlanta on Saturday night after scoring from second on Gleyber Torres’ RBI double in the fourth inning. Stanton, who led off the inning with a double, said on Sunday that he felt the hamstring tug when he rounded third.

“I knew it would be a few weeks,” said Stanton, who received a PRP injection on Sunday.

He went for an MRI on Sunday, which showed a “mild strain,” Boone said.

It’s a frustrating setback for Stanton, who, after a nightmare of a 2023 season, grew fed up with the array of lower-body injuries that had derailed more seasons than not in recent years.

Stanton, 34, completely remade his body last offseason, dropping about 20 pounds of muscle mass.

“Be a baseball player again,” he said early in spring training. “I just needed to be more mobile. A lot of setbacks [last season] kept me not moving the way I’d like to be.”

Stanton, who missed nearly six weeks last season with a left hamstring injury and ended up hitting .191 with 24 homers and a .695 OPS in 101 games, is hitting .246 with 18 homers, 45 RBIs and a .795 OPS in 69 games this season.

Other than his first season with the Yankees, when he played 158 games in 2018, his career with the club has been characterized by head-turning exit velocities but also a lot of time spent on the IL.

“My feelings really don’t matter at this time,” Stanton said of his frustration level at yet another lower-body injury. “It’s going to be about four weeks and I gotta do what I can to get there.”