The man was arrested at the local bus station.
When police received a report of a man armed with a knife near the bus depot in Derry they found a man with a 7 inch blade, the local magistrates court heard today.
Scott McElwee, 23, of Tamlough Park in Ballykelly, admitted possessing an offensive weapon in a public place on July 24 last.
The court was told that police were called at around 12.40pm after a report of a man being seen with a knife in Foyle Street.
The man was followed on CCTV and was seen going into the bus depot and going into the toilets.
Police responded and they approached and ordered McElwee to lie on the ground which he did and he told police he had a knife in his waistband.
At interview, McElwee told police he had been at home when he received a call from his pregnant girlfriend who was in Derry shopping saying that she had been intimidated by a family known to her.
He said he grabbed the knife and went to find his girlfriend.
He said he showed the knife to scare the other person.
Defence solicitor, Keith Kyle, said McElwee had pleaded guilty at the earliest opportunity.
He said he had no intention of actually using the knife and added that McElwee's 'decision making was not good at this time'
District Judge Barney McElholm the problem was if someone takes a knife to a fist fight it escalates things. Then the next thing someone takes a gun to a knife fight, added the judge.
He sentenced McElwee to two months in prison.
Subscribe or register today to discover more from DonegalLive.ie
Buy the e-paper of the Donegal Democrat, Donegal People's Press, Donegal Post and Inish Times here for instant access to Donegal's premier news titles.
Keep up with the latest news from Donegal with our daily newsletter featuring the most important stories of the day delivered to your inbox every evening at 5pm.