Re: newbie needs to format time field
| From: | Eric J Schwinder | Date: | Thu, 06 Sep 2001 04:22:04 +0000 |
| Subject: | Re: newbie needs to format time field | ||
| References: | 1 2 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-12205@lists.php.net to get a copy of this message | ||
thanks so much, I've gotten a lot from that page of the mySQL
documentation... but I'm still needing little more help. I am currently
using the following PHP to generate my page (with results displayed in
standard mySQL date and time formats):
$db = mysql_connect("localhost", "username", "password");
$result = mysql_query("SELECT * FROM table order by date",$db);
$myrow = mysql_fetch_array($result));
printf("%s",$myrow["date"]);
printf("%s",$myrow["time"]);
printf("%s",$myrow["description"]);
Should I change my query to something like this:
$result = mysql_query("SELECT *,DATE_FORMAT(date,'%m/%d/%y')) FROM
tableorder by date",$db);
I tried using that query, but then I didn't know how to get the formatted
date out of the array field in my PRINTF lines (what goes in the [" "]?)
Should I use two different queries, so that I have $result1 and $result2,
then $myrow1 and $myrow2, like this:
$result1 = mysql_query("SELECT * FROM table order by date",$db);
$result2 = mysql_query("SELECT DATE_FORMAT(date,'%m/%d/%y')) FROM table
order by date",$db);
$myrow1 = mysql_fetch_array($result1));
$myrow2 = mysql_fetch_array($result2));
Thanks for everyone's time.... if not for newsgroups, I don't how I'd learn
anything!
Eric Schwinder
eric.AT.bergencomputing.DOT.com
"Torgil Zechel" <torgil@problem.se> wrote:
> Checkout:
> http://www.mysql.com/doc/D/a/Date_and_time_functions.html
>
> the function DATE_FORMAT(date,format) does what you want...
>
> > I have a mySQL database that I am using PHP to interface with. I have
> > fields in the database that are DATE and TIME types. Can I format these
> > values so that the user sees "September 15, 2001" or "2:00 PM"
> > instead of
> > "2001-09-15" and "14:00:00" when I show the values on the web page?
> >