It depends on the manufacturer and/or type.
Ruger's website has a section showing serial numbers and year of manufacture. Others may also.
Forums for particular models like 1911's or S&W revolvers may have the information.
And some manufacturers will give you a "certified" history of the gun for a price, usually $50-$100.