changing car battery

How many years do car batteries last and how do I know if my car battery needs replacing?