Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jul 2004
    Location
    Tampa
    Posts
    223
    Thanks
    23
    Thanked 0 Times in 0 Posts

    Formatting time 00:00:00 and showing the hour

    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
    etc.

    Any help would be greatly appreciated.

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    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....

  • Users who have thanked Fumigator for this post:

    dprichard (03-05-2008)

  • #3
    Regular Coder
    Join Date
    Jul 2004
    Location
    Tampa
    Posts
    223
    Thanks
    23
    Thanked 0 Times in 0 Posts
    Thank you, that was exactly what I was looking for!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •