Results 1 to 8 of 8

Thread: Format Time in a Query

  1. #1
    Join Date
    Mar 2007
    Posts
    2

    Format Time in a Query

    In my table in SQL 2005 it has the date and time in the field. Example: 3/7/2007 9:14:00 AM. The question I have is how do you format this field so it displays 09:14:00 AM?

  2. #2
    Join Date
    Sep 2002
    Posts
    5,938
    Can try:

    convert(char(12), col_name, 108)

  3. #3
    Join Date
    Mar 2007
    Posts
    2
    That gives me 11:19:15 but no AM/PM

  4. #4
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    131 returns AM/PM but in dd/mm/yyyy format

    select convert(char(26),getdate(),131)

    There are several styles supported with CONVERT function, check BOL.

  5. #5
    Join Date
    Sep 2002
    Posts
    5,938
    There is no such style in convert function, may need use substring to get what you want.

  6. #6
    Join Date
    Feb 2009
    Posts
    7
    Hi,

    SELECT Substring('3/7/2007 9:14:00 AM', (CHARINDEX(' ','3/7/2007 9:14:00 AM'))+1, (CHARINDEX(' ','3/7/2007 9:14:00 AM'))+3)

  7. #7
    Join Date
    Sep 2002
    Posts
    5,938
    The thread is almost 2 years old.

  8. #8
    Join Date
    Feb 2009
    Posts
    7
    sorry i didnt check the date

Posting Permissions

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