Well, both ways are valid. There is no "right way" or "wrong way" as long as the output of both ways is valid, of course.
One thing I would look at though, is the fact that, depending on the time, there will be much more computation time for your method.
Example 12am:
1) test am/pm
2) test 12
3) return 00
Example 3am:
1) test am/pm
2) test 12
3) test 1
4) test 2
5) test 3
6) return 03
Example 11am:
1) test am/pm
2) test 12
3) test 1
4) test 2
5) test 3
6) test 4
7) test 5
8) test 6
9) test 7
10) test 8
11) test 9
12) test 10
13) test 11
14) return 11
Exactly the same number of steps for 12 am or pm, 3 am or pm, or 11 am or pm.
In contrast, the way I did it, performs 1 test (am or pm), 1 addition (if pm), and a sprintf(), which essentially has 3 or 4 steps for any time.
Example 12am:
1) test am/pm
2) set $hour to 12
3) set $hour to 12
Example 3am:
1) test am/pm
2) set $hour to 3
3) set $hour to 03
Example 11pm:
1) test am/pm
2) add 11 & 12
3) set $hour to 23
4) set $hour to 23
For 12, 1 or 2 (am OR pm), your code may be slightly quicker since no addition or sprintf()s are used, assuming that the convert_hour() function takes no appreciable time to call.
For 3 until 5 (am OR pm), our codes will probably execute in about the same time.
After 5 (am OR pm), my code may be slightly faster.
Now, you have to keep in mind that relative speed (faster or slower) is not really appreciable in with such a low number of lines and a single call. We could be talking the difference between 2 and 3 milliseconds in the worst cases (I'm guessing at these times...I haven't timed them!).
The only time this may become a factor is when you have a HUGE site with thousands of concurrent connections, all converting this time for each and every page they visit. But, even then, the extra time will be very small.
I hope this helps!
-Rich