It depends on the airline and their planning capacity. The simple answer is that they can't be sure of the tail number "of record" for a flight until the plane pulls into the gate at its destination. It's rare for a plane that departs the gate for a flight to not run that flight (it's pretty bad business for it to be common for flights to depart the gate and then come right back, or to be diverted, or otherwise not finish the route they left the gate to fly); it indicates a mechanical issue exists that did not develop and/or was not discovered until taxi or takeoff, and at some point in the flight (probably when departure control hands them off the the ARTCC) the plane could be said to have "run" the flight even if it ended up diverted.
Most of the equipment schedules (which tail number will fly which route at exactly what departure and arrival times) are generated by computer and can be set up months in advance if they really wanted to. However, that's usually an exercise in futility along the lines of predicting the weather more than a few days ahead. Airline scheduling, like weather, is susceptible to "chaos theory", because small deviations from the initial plan tend to compound over time instead of factoring out.
Ticket sales, rebooks and cancellations will affect the schedule days and weeks in advance of the flight. It's technically illegal to cancel a flight less than a certain number of days before its scheduled departure if it has even a single paying customer on the roster, but if a route is underperforming, the scheduler can reduce the scheduled daily flights along that route which could bump people who bought a ticket far in advance. Also, an underbooked flight can legally be cancelled if the plane is needed for an equipment change on a fuller flight, as cancelling the underbooked flight would cause less overall disruption than cancelling the full flight because that plane can't make its next hop.
I just mentioned mechanicals; that's a big reality check for a computer-generated schedule. If a plane cannot continue because of a mechanical defect, it gets pulled for maintenance. Airlines typically have a few planes parked strategically on the tarmac of various airports for a day, which can be activated to run a route, but they don't have too many of these since a parked aircraft isn't making money, and there isn't always one of these standby aircraft readily available as a substitute (though if a defect is found in flight the replacement can be on the way before the defective one lands to reduce the delay). Meanwhile, mechanicals are typically such a localized problem that the schedulers can't get away with just delaying flights systemwide, like they can often do with severe weather. They have to run the rest of their fleet on time, and that means either getting a replacement plane to the gate, pronto, or else sending that replacement plane empty to the cancelled flight's next destination, so the new plane can get those passengers on to their destination.
Obviously, severe weather can cause major ripples through an airline's schedule for days to come. If ORD or DFW has a "ground stop" due to severe precipitation or high winds, that will delay not only the flights scheduled to arrive or depart in that time, but every flight those tail numbers were scheduled to run for the rest of the day, as well as various scheduled connectors (those connecting flights, if they're not also under severe weather, often have to depart with whatever passengers they have otherwise there will be even more delays; then the passengers who have missed that connectot will have to be rebooked, on other airlines if need be).
That delay time also counts as "active" time for a flight crew; if a flight is delayed beyond a crew's end of shift, they often must get off the plane to comply with FAA regs and union CBAs. The scheduled replacement crew, however, was supposed to get on at the next stop hundreds of miles away; so, it's not just the planes that have to be replaced on a route when a flight is cancelled. In cases of a severe delay extending beyond a normal shift change, the crew either flies the plane if it's legal and are paid overtime, or if it would be illegal for that crew to continue, an on-call crew is brought in, flies the plane to the scheduled changeover point, then rides a standby seat (or in the extreme an empty plane) back to their home terminal or somewhere else they'll be useful when their shift really starts.
All of these considerations and more are weighed by the sophisticated algorithms now used to generate flight schedules. American Airlines calls theirs the "cancellator", and when a major hub like DFW, ORD or ATL sees a weather shutdown that's pretty much exactly what it does, sacrificing flights to and from that hub and some of its connectors to try to save what it can of its passenger load for the day (and thus the airline's profitability for the quarter).