Forum Moderators: coopster
function date_convert($date){
$date_year=substr($date,0,4);
$date_month=substr($date,5,2);
$date_day=substr($date,8,2);
$date=date("F jS, Y", mktime(0,0,0,$date_month,$date_day,$date_year));
return $date;
}
echo date_convert($row['date']); //// $row['date'] is in the form :September 11, 2007
This echoes nothing. Can you help me out?
If all you want to do is convert the mysql date, use DATE_FORMAT [dev.mysql.com]. Let the database do the work.
dc
echo $date_row['date'];
Doesn't Work.
I tried execute this in phpmyadmin too.
SELECT DATE_FORMAT('date', '%m %e %Y') from table
It returned :
--------------------------------------------
DATE_FORMAT( 'date' , '%m %e %Y' )
--------------------------------------------
NULL
--------------------------------------------
NULL
--------------------------------------------
NULL
--------------------------------------------
$date_row = mysql_fetch_assoc($date_result);
echo $date_row['new_date'];
Even This doesn't work. Nothing is echoed. No mysql error is displayed either.
The 'date' column's data type is TEXT and the date is in the form of :
September 24, 2007
$date = "SELECT DATE_FORMAT('date', '%m %e %Y') AS new_date FROM shares";$date_result = mysql_query($date);
$date_row = mysql_fetch_assoc($date_result);print_r($date_row)
echo $date_row['new_date'];
I have removed an extra ";" in your query.
I have removed the mysql_query (even in the if condition it does execute, I believe)
Added print_r, to see if you are having any data in the array.
Habtom
If you have a table1 , and (fields date which is varchar(100) you can also convert it as date type look the following examplemysql> select str_to_date(date,'%d/%m/%Y') as Mydate from table1 order by Mydate DESC;
maybe try something like that