Update 2021-12-05: in response to the Omicron variant, for flights departing at or after 12:01 AM EST on December 6, 2021, the COVID test has to be done 1 day before the flight departure. Source: CDC order.
Since OP couldn't find the information in my previous link, I'll add some quotes here:
This Notice and Amended Order supersede the previous Order signed by the CDC Director on October 25, 2021. This Order shall enter into effect for flights departing at or after 12:01 a.m. EST (5:01 a.m. GMT) on December 06, 2021. [...] Documentation of a negative SARS-CoV-2 viral test result from a specimen collected no more than 1 calendar day preceding the passenger’s flight to the United States.
Why does the Order specify 1 day rather than 24 hours? What is considered 1 day?
The 1-day period is 1 day before the flight’s departure. The Order uses a 1-day time frame instead of 24 hours to provide more flexibility to the air passenger and aircraft operator. By using a 1-day window, test acceptability does not depend on the time of the flight or the time of day that the test sample was taken.
For example, if your flight is at 1pm on a Friday, you could board with a negative test that was taken any time on the prior Thursday.
I'm flying on Wednesday. Does this mean I can get the test on Sunday/Monday/Tuesday?
Yes, as far as the US is concerned.
I'd advise to do the test within 72h if possible or if not call the airline while recording the call, because some airline employees, such as some Qatar Airways employees I've encountered, can't read properly and mistakenly think 3 days = 72h, or may have their own policies.