Dean Murphy, 18, was stopped by the two plain-clothed officers in Cheshunt High Street last September.
St Albans Crown Court heard Murphy stabbed one in the arm and the other across his hands as he tried to flee.
Murphy, of Caledonian Road in Islington, London, admitted a weapons, assault and wounding charge.
The court heard the two detectives - Det Con Donald Ayriss and Det Con Daniel Bardwell - showed Murphy their warrant cards before he attacked them.
Murphy pulled out a knife which Det Con Ayriss's blocked with his arm.
Det Con Bardwell was injured in the hand and fingers as he detained Murphy, who the court heard was a father to a two year old child.
David Rhodes, defending, said Murphy, who has three convictions for carrying knives, had grown up in a tough area of London where knife crime was prevalent.
He was armed, said Mr Rhodes, to protect himself.
Recorder Ann Mulligan sentenced Murphy to six years and three months for wounding with intent to resist the lawful apprehension.
He was also sentenced to nine months in an institution for the assault on Det Con Bardwell and six months for carrying a knife, both to be served concurrently with the custodial sentence for wounding.
A teenager who stabbed two policemen in a bid to escape questioning has been sentenced to more than six years in a young offenders' institution.