The forty years refers to the time from when David “won” the hearts of the Israelites (I Samuel 18:5) to the time when Absalom “stole” their hearts (II Samuel 15:6).