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

Reply via email to