Sunscreen usually lasts for at least 3 years before it goes bad, and after this time, it becomes less effective at blocking UV rays, increasing your chances of getting sunburn or skin cancer.
However, if your bottle is less than 3 years old but it’s been left in a hot car for a couple of months, it probably won’t be very effective, either.