It was before. He wore it in January 2005, and went to Sandhurst in May 2005. But he'd been accepted in September 2004, amid a certain amount of fanfare, so refusing to take him after all would have caused quite a fuss.
The surprising thing, to me, was that he was commissioned after not only referring to one of his fellow-soldiers by a derogatory word for somebody from Pakistan, and another as a towel-head, but for god's sake filming himself doing it and then publishing the film! "Too much of an idiot for us to commission" would have been the verdict on anyone else, at that point: he would just have been one more who was dropped out for whatever reason. It would only have taken the one occasion (which I think was all there was).
Even if he did spend his time in Afghan playing X Box and lollygagging, he was still in a place where someone might suddenly decide to start killing people – at a meal, or anywhere at random. That will have had an effect on him as on everyone else; and he would have been more of a target than most because of who his family was, so even if he had a security detail it would have been more immediate for him as something to be aware of at all times. That can't be easy.
Doesn't excuse being an arse, but may explain it.