Several members of the public called police over in the incident near to Dewsbury and District Hospital
Police were called after a man was seen carrying a Samurai sword as he walked towards a hospital, a court heard.
A witness dialled 999 after seeing Jamie Holdsworth brandishing the weapon and muttering something about threatening to kill someone, Kirklees magistrates were told.
He was allegedly seen close to Dewsbury and District Hospital before another witness called police 20 minutes to say they had also seen the 35-year-old.
Police were dispatched and they found Holdsworth on Owl Lane, Shaw Cross, where he allegedly dropped the sword on the ground and told them: “I’m guilty as charged.”
He denies a charge of possession of an offensive weapon in public.
Magistrates told him that his trial will take place in the Huddersfield court on May 31.
Holdsworth, of Windsor Gardens in Shaw Cross, Dewsbury, was granted unconditional bail in the meantime