How soon would you know if a comet was going to hit the earth?

Because comets are composed of ice and dust, they are often easily seen several months prior to their perihelion; usually around the distance of Mars or the asteroid belt, and sometimes further out than Jupiter is. A global network of amateur astronomers, searching nightly for comets, would almost certainly see any comets while still far out from the Earth. We could expect a minimum of 3 months warning, and possibly 9-12 months before it would hit the Earth.

So far, nothing that we have detected in space has more than one chance in several thousand of striking the Earth. That body, the asteroid "Apophis", will certainly miss the Earth on its first approach on Friday, April 13 2029, but Earth's gravity may distort its orbit so that Apophis has a SLIGHT chance of collision on its second encounter on Friday, April 13, 2036.

The fact that both dates are Friday the 13th is not lost on astronomers.