Jason Dyer was stopped and searched on Cavendish Road, Manton, on November 24, last year, said prosecutor Daniel Pietyrka.
He was found with seven wraps of cocaine, along with £130-£200 of cannabis.
At 10.30am, on December 12, officers found him in a drunken state and carrying a knife in his coat pocket.
There was a big gap in his offending between 2011 and 2020, the court heard.
Nigel Misson, mitigating, said Dyer had been going through a very difficult time recently.
Dyer, 49, admitted both offences, when he appeared in court on Thursday.
He was sentenced to four months, suspended for 15 months. He was also ordered to carry out 15 days of rehabilitation to tackle his misuse of alcohol.
He must also pay £85 costs and a £128 victim surcharge.