Born in Hamburg, Hansen entered the army of Imperial Germany in 1907 as a Fahnenjunker (officer cadet) in the 9th Dragoons. He was given command of the 4th Infantry Division in 1938. Promoted to generalleutnant[Note 1] in August 1939,[2] he led the division through the invasion of Poland and the French Campaign before it was withdrawn from the front in August 1940 for conversion to armour.