Change your query, mySQL provides some powerful formatting functions for
doing exactly what you want:
SELECT id,
fname,
lname,
DATE_FORMAT( date, '%m/%d/%Y' )
FROM tablename where date >= '$year_1-month_1-$day_1-'
AND
date <= '$year_2-$month_2-$day_2';
Cheers,
Rob.
-------------------
Steve Bradwell wrote:
>
> Hey Alex,
>
> I use a short function like this because the date is really just a string
> you can pick it apart and re-arrange it.
>
> function Format_Date($Date){
> return $Date =
> ((substr($Date,6,2))."-".(substr($Date,0,2))."-".(substr($Date,3,2)));
> }
>
> Steve.
> -----Original Message-----
> From: Alex [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, April 16, 2002 1:36 PM
> To: [EMAIL PROTECTED]
> Subject: [PHP] format date
>
> I just started with php and am trying to display a query result for a date
> field as mm/dd/yyyy instead of mysql's yyyy-mm-dd. I looked through some
> books and found the use of DATE_FORMAT to covert the dates. Is there any
> other way to format the date?
>
> Thanks
>
> My script looks like this:
>
> $month_1 = ($date_month_1);
> $day_1 = ($date_day_1);
> $year_1 = ($date_year_1);
> $month_2 = ($date_month_2);
> $day_2 = ($date_day_2);
> $year_2 = ($date_year_2);
>
> $query = "SELECT * FROM tablename where date >= '$year_1-month_1-$day_1-'
> AND
> date <= '$year_2-$month_2-$day_2'";
>
> $result = mysql_query($query);
>
> $num_results = mysql_num_rows($result);
>
> echo "<p>Number of records found: ".$num_results."</p>";
>
> for ($i=0; $i <$num_results; $i++)
> {
> $row = mysql_fetch_array($result);
>
> echo "<p><strong>".($i+1).". ID: ";
> echo ($row["id"]);
> echo "</strong><br>First name: ";
> echo ($row["fname"]);
> echo "<br>Last name: ";
> echo ($row["lname"]);
> echo "<br>Date: ";
> echo ($row["date"]);
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
--
.-----------------.
| Robert Cummings |
:-----------------`----------------------------.
| Webdeployer - Chief PHP and Java Programmer |
:----------------------------------------------:
| Mail : mailto:[EMAIL PROTECTED] |
| Phone : (613) 731-4046 x.109 |
:----------------------------------------------:
| Website : http://www.webmotion.com |
| Fax : (613) 260-9545 |
`----------------------------------------------'
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php