Rachel Knight, prosecuting at Merthyr Tydfil Crown Court, said Smith, of Treorchy, had gone to the Barclays Bank branch in Treorchy, on April 15 to change his address.
But just 30 minutes later, Smith was seen on CCTV wearing a jacket with his hood up, socks over his shoes, and sunglasses, rush up to the glass partition and demand money from cashier Catherine Stockton.
She could see that he was holding a bread knife across his body as he demanded all the cash to be handed over.

“He was not shouting. He was rushed but not angry or agitated. He sounded desperate,” said Ms Knight.
She raised the alarm by pressing the panic button as she tried to keep the situation calm and it was only when he heard that they planned to lock the doors that he left.
“After the incident, they closed the bank and made a cup of tea for the elderly gentleman,” said Ms Knight.
“Since the incident, Ms Stockton has been very wary about people who look like him. She can’t help thinking about it every time a young person comes into the bank.

“She was very thankful nobody was injured.”
Smith told police that he had been inspired to carry out the robbery after seeing the tills full of money on his earlier visit.
Steven Jeary, defending Smith, who admitted attempted robbery and having an article with a blade, said: “He told the police it was stupid and he was very sorry but he was desperate for money.”
Judge Richard Twomlow jailed him for two and a half years.
He will also have to pay a £120 victim surcharge.