How do I convert the time to HH:MM am/pm from database's HH:M:SS?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • triathlontim

    #1

    How do I convert the time to HH:MM am/pm from database's HH:M:SS?

    I'm using Dreamweaver CS5 and my recordset looks like this:
    Code:
    SELECT database.`TIME`
    FROM database
    ORDER BY database.`TIME`
    All of the times are input into the database as HH:MM:SS, so they are returned that way. I need to have them displayed on my web page as HH:MM AM or PM.

    Obviously, I'm new to this. Any ideas?

    Thanks!
  • JKing
    Recognized Expert Top Contributor
    • Jun 2007
    • 1206

    #2
    You can use the DATE_FORMAT function. http://dev.mysql.com/doc/refman/5.1/...on_date-format

    Comment

    • triathlontim

      #3
      Got it. Now where does it go in my code?

      SELECT DATE_FORMAT('20 07-10-04 22:23:00', '%h:%i %p');

      Does it go in my recordset somewhere?

      SELECT database.`TIME`
      FROM database
      ORDER BY database.`TIME`

      Thanks for your help!

      Comment

      • JKing
        Recognized Expert Top Contributor
        • Jun 2007
        • 1206

        #4
        You use the function on your time field.

        Code:
        SELECT DATE_FORMAT(database.`TIME`, '%h:%i %p')
        FROM database
        ORDER BY database.`TIME`

        Comment

        • triathlontim

          #5
          When I test it through Dreamweaver's recordset test, it works, but when I implement it onto the page, it gives me errors.

          Undefined index: DATE_FORMAT(sch edule.`TIME'in C:\wamp\www\mys ite.php on line 288

          Comment

          Working...