Police were called after a man was spotted outside a town centre bar with a knife.
Officers went to New York, New York in Town Hill, Wrexham, shortly after 3am on August 13 after Mark Haydn Samuels, 33, was seen with a knife in his back pocket.
Samuels had been out with his girlfriend but they had separated after an argument and Samuels, of Bennions Road, went home.
But after he rang her and someone else answered her phone, Samuels went back out to find her, taking a five-inch kitchen knife with him.
When officers arrived, Samuels was talking to door staff.
They asked him to move away and show his hands before telling Samuels they would have to conduct a search.
But as PC Stuart George went to restrain Samuels so he could be searched, he shouted at the officer to get his hands off him and began to struggle.
With the help of colleagues, PC George managed to move Samuels to the bonnet of the police car, where he continued to struggle.
The knife was found in the rear right pocket of his jeans.
During the struggle, the knife fell to the floor but it was retrieved by one of the officers.
Appearing before Wrexham Magistrates Court, Samuels admitted possessing a knife in public and resisting a constable in the execution of his duty.
Rhian Jackson, prosecuting, said Samuels had the knife because he wanted to harm himself.
He was intoxicated and behaved in an erratic manner while being taken to custody.
Interviewed, Samuels said he had been waiting for the door staff to get his girlfriend out of the bar when police arrived.
He could remember officers arriving but did not recall them explaining they wanted to search him.
Samuels said he resisted because he did not like being touched.
The court heard he had a previous conviction for a similar offence dating back to 2001.
Patrick Geddes, defending, said there was no suggestion Samuels had been brandishing the knife and it was never his intention for it to be used.
Samuels, who has a long history of mental illness, took it with the intention to harm himself.
Sentencing Samuels to 26 weeks in prison for the possession of a knife and a further two weeks for the resisting an officer charge, both suspended for a year, district judge Gwyn Jones said: “A knife is a dangerous weapon which can cause really serious harm or death.
”You were under the influence of drink and this incident was in a very sensitive area of Wrexham during the early hours of the morning where a number of other revellers were present outside licensed premises.
“It is also clear you had been in an argument with your girlfriend earlier in the evening and were feeling aggrieved.”
Mr Jones also imposed a six-month curfew to run from 7pm to 6am and ordered Samuels to pay a £115 victim surcharge and £85 costs.
A forfeiture and destruction order was made for the knife.