Hello, I just started with php and I'm also trying to format mysql date yyyy-mm-dd into mm/dd/yyyy. I looked through some books and they describe the use of DATE_FORMAT to covert the dates. Is there any other way to format the date? Thanks Alex
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"]); "Justin French" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > There is a difference between MySQL's timestamp, and a UNIX timestamp. > > strtotime(); is a really valuable tool -- converting almost any English date > description -- check out the manual for more info. > > Anyway, in this case, it is able to convert your MySQL date of 20020409 into > a unix timestamp, which is the required format for date() formatting. > > > In clear code: > > <? > > $date = "20020409"; > $date_unix = strtotime($date); > $date_f = date('jS M Y',$date_unix); > echo $date_f."<BR>"; > > ?> > > Although this can be condensed to: > > <? > $date = "20020409"; > $date_f = date('jS M Y',strtotime($date)); > echo $date_f."<BR>"; > ?> > > or even just > > <? > $date = "19770417"; > echo date('jS M Y',strtotime($date)); > ?> > > > Check out: > http://www.php.net/manual/en/function.date.php > http://www.php.net/manual/en/function.strtotime.php > > for more info and date() formats. > > > Note: I haven't done a heap of testing with strtodate() to ensure it's going > to return what you expect, but I randomly tested 10 dates in your format > between 1977 and 2002 without any problems. > > > Justin French > -------------------- > Creative Director > http://Indent.com.au > -------------------- > > > > > on 09/04/02 9:53 PM, nyon ([EMAIL PROTECTED]) wrote: > > > Hi, > > > > I need to recall a date data in a MySQL database. > > The column is set as "date timestamp(8)". > > A sample of date is "20020409" > > > > I use the PHP Date function to format it back to say "9th April 2002". > > $date_formated = date($date, 'S M Y' ); > > However, it's still doesn't appear as formatted. > > > > Anyone mind sharing their code to do this? > > > > Nyon > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php