Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-12-2012, 07:10 PM   PM User | #1
howie2009
Regular Coder

 
howie2009's Avatar
 
Join Date: May 2009
Location: Ireland
Posts: 202
Thanks: 37
Thanked 0 Times in 0 Posts
howie2009 is an unknown quantity at this point
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
howie2009 is offline   Reply With Quote
Old 06-12-2012, 07:29 PM   PM User | #2
Keleth
Senior Coder

 
Join Date: Jun 2008
Location: New Jersey
Posts: 2,354
Thanks: 45
Thanked 247 Times in 244 Posts
Keleth is on a distinguished road
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'.
Keleth is offline   Reply With Quote
Old 06-12-2012, 07:33 PM   PM User | #3
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,752
Thanks: 4
Thanked 2,468 Times in 2,437 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:23 AM.


Advertisement
Log in to turn off these ads.