SAN DIEGO — The federal government has six months to identify potentially thousands of children who were separated from their families at the U.S.-Mexico border early in President Donald Trump's term, a judge ordered Thursday.

Trump administration officials said they had a goal of six months but opposed any deadline, saying it could take as long as two years to reunite children with their parents if efforts to speed up the process fail.

U.S. District Judge Dana Sabraw said he would be willing to consider an extension past Oct. 25 but that he wanted to establish a firm date.

"It is important for all government actors to have a timeframe, a deadline," he said. "You tend to stand on it."

The administration will review about 47,000 cases of unaccompanied children in custody between July 1, 2017 and June 25, 2018 — the day before Sabraw halted the general practice of separating families and ordered that children under government care at the time be reunited in 30 days.

More than 2,700 children had been separated when Sabraw issued his June order and they have largely been reunited. Then, in January, the internal watchdog for the U.S. Health and Human Services Department reported that thousands more children may have been split since summer 2017. The department's inspector general said the precise number was unknown.

Jonathan White, a commander of the U.S. Public Health Service and Health and Human Services' point person on family reunification, testified for about an hour on how he would oversee the effort. After he spoke, the judge praised his continued involvement, calling him "a beacon of light."

The administration will develop a statistical model within 12 weeks to search for factors most likely for separations. Those factors, detailed in an earlier court filing, include children under 5, younger children traveling without a sibling and those detained in the Border Patrol's El Paso, Texas, sector, where the administration ran a trial program that involved separating nearly 300 family members from July to November 2017.

On a parallel track, the administration will begin work immediately on identifying children who were separated after U.S. Customs and Border Protection introduced a tracking system in April 2018.

The government lacked tracking systems when the administration began a "zero tolerance" policy a year ago to criminally prosecute every adult who entered the country illegally from Mexico, sparking an international outcry when parents couldn't find their children.

Poor tracking before April 2018 and the fact that still-separated children are no longer in U.S. custody complicates the latest task.

The vast majority of separated children are released to relatives, but many are not parents. Of children released in the 2017 fiscal year, 49 percent went to parents, 41 percent to close relatives such as an aunt, uncle, grandparent or adult sibling and 10 percent to distant relatives, family friends and others.

White told the judge that six months was his "operational target" but that he's been wrong before and there were still lots of unknowns about the process.

The American Civil Liberties Union, which sued over family separations, wanted the job done in three months, which White said was unrealistic. The ACLU agreed Thursday to six months.

"This order shows that the court continues to recognize the gravity of this situation," ACLU attorney Lee Gelernt said after the hearing.