View Full Version : Formatting time 00:00:00 and showing the hour

03-05-2008, 06:02 PM
I have a field in my database that stores the start and stop times for employee's shifts. If they start at 8am it stores it as 08:00:00. I am trying to figure out how to display it as just the number 8 for my start time. I looked at the date function and saw that H will return just the hour, but I get errors when I try to get it to format correctly.

So, in a nutshell, I need to display

08:00:00 as 8
17:00:00 as 17

Any help would be greatly appreciated.

03-05-2008, 06:28 PM
Is this a "time" data type column? If so you can just do SELECT HOUR(columName) FROM yourtable. You can also use SELECT TIME_FORMAT(columnName, '%H') FROM yourtable.

If it's not a "time" data type column.... well....

03-05-2008, 07:42 PM
Thank you, that was exactly what I was looking for!