Paint can last for years if the top of the can has not been opened. Many times paint will outlast the life of a can if it has been rusted. You also need to be careful if you shake a rusted can as it’s possible it could easily break which would create an unfortunate mess!
If a can has been opened it won’t last for more than two years and for latex even less. It’s always a good idea to save leftover paint for touchup jobs and we recommend writing the date on the lid so you know how long it’s been since it was used.
After two years its best to dispose of the paint properly. Latex paint will probably freeze and the pigments in the oil paint will settle and a skin will form on the top.