Results 1 to 7 of 7

Thread: How to display time in 12 hour format?

  1. #1
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    602
    Thanks
    266
    Thanked 13 Times in 13 Posts

    Default How to display time in 12 hour format?

    I looked up on php.net the proper format for displaying date and time and it said to use %a to show am or pm.

    I am using this command

    Code:
    time_format(`starttime`, '%h:%i ') as time
    which works just fine until I add the %a, and then that column gives all nulls.

    Why does this not work?

    Code:
    time_format(`starttime`, '%h:%i %a') as time
    If %a is wrong, how do you display am and pm??

    Thanks, e
    Last edited by kuau; 07-18-2008 at 04:30 AM. Reason: sp

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Use %p. You can see more info at the following website:

    http://www.eltcalendar.com/stuff/datemysqlphp.html

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. The Following User Says Thank You to thetestingsite For This Useful Post:

    kuau (07-18-2008)

  4. #3
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    602
    Thanks
    266
    Thanked 13 Times in 13 Posts

    Default

    Great link. Thanks. Yes!! That worked.. thanks so much. I had wanted lowercase am/pm but that does not seem possible (none obviously didn't work). I'll settle for uppercase.

  5. #4
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    602
    Thanks
    266
    Thanked 13 Times in 13 Posts

    Default

    Actually, the uppercase AM and PM are too big now that I see them on the page. Any idea how to make them lowercase considering my variable ends up like below? Your link says that you use a small "a" to designate this in php but that didn't work in this command.

    Code:
    time_format(`starttime`, '%h:%i %p') as time
    This is my display variable:

    Code:
    $event['starttime']   = $row2['time'];

    Thanks, e

  6. #5
    Join Date
    Jul 2008
    Location
    Johannesburg, South Africa
    Posts
    31
    Thanks
    1
    Thanked 10 Times in 10 Posts

    Default

    How about...

    Code:
    (time_format(`starttime`, '%h:%i') . strtolower(time_format('starttime', ' %p'))) as time
    Hope it helps
    Last edited by GarethMc; 07-21-2008 at 09:32 AM. Reason: Syntax correction

  7. The Following User Says Thank You to GarethMc For This Useful Post:

    kuau (07-21-2008)

  8. #6
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    602
    Thanks
    266
    Thanked 13 Times in 13 Posts

    Default

    Actually that is what I ended up using, but then I decided not to use the time_format command because it caused unexpected results. So once it became php I was able to use:

    Code:
    $endtime  = date('g:i a', strtotime($row['endtime']));
    Thanks! e

  9. #7
    Join Date
    Jul 2008
    Location
    Johannesburg, South Africa
    Posts
    31
    Thanks
    1
    Thanked 10 Times in 10 Posts

    Default

    Quote Originally Posted by kuau View Post
    Actually that is what I ended up using, but then I decided not to use the time_format command because it caused unexpected results. So once it became php I was able to use:

    Code:
    $endtime  = date('g:i a', strtotime($row['endtime']));
    Thanks! e
    Hehe .. well .. I always use the date() function myself ... would have been my next suggestion.. >.<

Bookmarks

Posting Permissions

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