Hammer's career was interrupted in 1848 by the outbreak of Denmark's Three Years' War with Prussia over hegemony in the Duchy of Schleswig. He volunteered and was commissioned as a lieutenant in March 1849. In the years following Denmark's fragile victory, he remained on active duty with the rank of captain before shifting to the reserves and finally leaving the service entirely in 1860.