PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
vchris
Forum Contributor
Posts: 204 Joined: Tue Aug 30, 2005 7:53 pm
Location: Canada, Quebec
Post
by vchris » Sat Sep 17, 2005 1:58 pm
I am trying to display the time like this: "1:05 pm". But it seems php can't get the "pm" and the 1 digit hour.
Here is what I got:
Code: Select all
$query = "SELECT newsid, newsheadline, newscontent, DATE_FORMAT(newsdate, '%M %d, %Y %g:%i %a') AS nd FROM news ORDER BY newsdate DESC";
%g should get the 1 digit hour and %a the pm or am.
This is what I have in the database:
9/15/2005 5:07:10 PM
This is what I have displayed:
September 15, 2005 g:54 Thu
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Sep 17, 2005 2:03 pm
you're assuming MySQL supports the same format parameters as PHP's date() function, which it does not.
Have a read through the DATE_FORMAT() section here:
http://dev.mysql.com/doc/mysql/en/date- ... tions.html
vchris
Forum Contributor
Posts: 204 Joined: Tue Aug 30, 2005 7:53 pm
Location: Canada, Quebec
Post
by vchris » Sat Sep 17, 2005 2:44 pm
Thanx I got it now.
How would I insert a certain date with mysql depending on the date the user choosed in drop-downs?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Sep 17, 2005 2:59 pm
format it to MySQL's format for the column type or convert it to a unix timestamp and pass that to MySQL's FROM_UNIXTIME() function.
vchris
Forum Contributor
Posts: 204 Joined: Tue Aug 30, 2005 7:53 pm
Location: Canada, Quebec
Post
by vchris » Sat Sep 17, 2005 3:12 pm
I'm able to format the date but only thing is how can I have the AM or PM added at the end? is it even possible or would I have the user choose times from 1 to 24?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Sep 17, 2005 4:44 pm
there are several possibilities:
0-23, 1-24
12AM-11PM
1-12 with a radio, checkbox, combo selector