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

Thread: PHP date

  1. #1
    Regular Coder howie2009's Avatar
    Join Date
    May 2009
    Location
    Ireland
    Posts
    204
    Thanks
    37
    Thanked 0 Times in 0 Posts

    PHP date

    Hi Guys,
    PHP will typically output time using
    Code:
     %g:%i%a
    as 8:00pm. How do I get time to be outputted as 8 p.m if there are no minutes with a dot between p and m. Same for am.
    Any ideas?
    Thanks

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,542
    Thanks
    45
    Thanked 259 Times in 256 Posts
    The PHP date has function function doesn't have anything to put a dot between the letters. You'll have to do a conditional to check if date('a') == 'am', and if so, echo 'a.m', and if not, echo 'p.m'.

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    I'm not sure what you're parsing. Date doesn't use %'s within its format and shows literally, while strftime doesn't use g:i:a to indicate its hour minute and am/pm representative. That would be %I:%M:%P.
    There is no way to add the . between the a and m. That requires manual insertion instead:
    PHP Code:
    if (strftime('%p'$iTime) == 'AM')
    {
        
    $sTime strftime('%I:%M a.m'$iTime);
    }
    else
    {
        
    $sTime strftime('%I:%M p.m'$iTime);
    }

    print 
    $sTime


  •  

    Posting Permissions

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