I was 28 when I retrained and stopped bumming about going dead end job to dead end job. Doing rather well in my new line of work and ive worked/trained my way up nicely. I had a considerable period in between where I wasn't exactly taking it seriously as well, needed to sort my life out outside of work which ive now done.
I'd say it's reasonable to retrain at 40 and make a good go of things.