The man, who cannot be named for legal reasons, parked in the White Hart pub car park while temperatures hit 20 degrees C, on April 21, and two passersby rang 999.
“The car was in the full glare of the sun and the young boy seemed to be in a distressed state,” said prosecutor Daniel Pietryka.
“He was wearing a fleece jacket and seemed to be sweating.
Fire crews deployed to ‘large’ blaze in Mansfield – with people evacuated as flames spread to nearby properties
Letter: Unfair that disabled can no longer access water park
Creswell properties evacuated as fire crews tackle field blaze
Large fire in Kirkby may have been a 'deliberate or a careless act'
New council boss reveals ambitious plans for Mansfield
“The vehicle window had to be smashed so they could get the child out of the car.”
The little boy was given fluids when he was released.
The boy’s father later told police he had purchased a one-hour car park ticket and had intended to buy a gift for his partner’s colleague.
But when officers rang his mobile he was in the betting shop, having withdrawn £190 from the bank.
“He thought the weather was mild at the time,” added Mr Pietryka.
Michael Little, mitigating, said the boy’s father had no previous convictions, and he left the boy in the car for 22 minutes, with all four windows open about an inch.
“He says: ‘I will never let this leave me to the day I die.’” said Mr Little.
He said the man was handcuffed in front of his son and spent six hours in police interview before he was able to find out how the boy was doing.
He also moved out of the family home during a social services assessment, but no concerns had been raised.
He said the man has had an “on-off” gambling problem for the last three to four years, but had not gambled since the incident, and he has joined Gamblers’ Anonymous.
Probation officer Mark Burton said: “I put it to him that he was gambling with his son’s wellbeing, to which he replied: ‘One hundred per cent’.
“He recognises that his paternal care practises will be subject to close scrutiny at least in the short term.”
JP Jennifer Wood said: “Clearly you’re remorseful. I have no doubt you will never do this ever again.
“It is still a very serious offence. He wasn’t even old enough to open the car door. He was fastened in a car seat. Fortunately he wasn’t hurt.”
The boy’s father was given an eight-week prison sentence, suspended for 12 months, and he must complete 10 days of a rehabilitation activity requirement to focus on his thinking skills.
He must pay £85 costs and a £115 government surcharge.