Same thing happened to a friend of mine 30 odd years ago.
DD charge. He drove himself to court (genuinely) believing that the magistrate would allow him to drive himself home again after imposing a ban.
Got banned. Went to his car, started it up, immediately arrested, taken back inside the court and given a one month jail sentence (on the same day).
Not the brightest