I am having trouble formating the dates that are being returned from my mySQL database.
Here is the code that I am trying to use:
<?php
function get_gold_time()
{
$goldquery = mysql_query("SELECT * FROM metal_price WHERE metal= 'GOLD' LIMIT 0, 96");
while($result = mysql_fetch_array( $goldquery ))
{
echo "'" . date_format($result['time'], 'jS ,g A') . "'" . ", " ;
}
}
?>
This is the error I receive:
Warning: date_format() expects parameter 1 to be DateTime, string given in /home/bellsnet/public_html/chart.php on line 128
”,
Without the date format my code looks like this:
<?php
function get_gold_time()
{
$goldquery = mysql_query("SELECT * FROM metal_price WHERE metal= 'GOLD' LIMIT 0, 96");
while($result = mysql_fetch_array( $goldquery ))
{
echo "'" .$result['time'] . "'" . ", " ;
}
}
?>
And is returning my values as follows:
'2011-08-10 01:15:02', '2011-08-10 01:00:02', '2011-08-10 00:45:02', '2011-08-10 00:30:02', '2011-08-10 00:15:02', '2011-08-10 00:00:02', '2011-08-09 23:45:03', '2011-08-09 23:30:02', '2011-08-09 23:15:02', '2011-08-09 23:00:03', '2011-08-09 22:45:02', '2011-08-09 22:40:22', '2011-08-09 22:30:02', '2011-08-09 22:15:02', '2011-08-09 22:13:41', '2011-08-10 02:00:02', '2011-08-10 01:45:02', '2011-08-10 01:30:02', '2011-08-10 02:15:02', '2011-08-10 02:30:02', '2011-08-10 02:45:02', '2011-08-10 03:00:02', '2011-08-10 03:15:03', '2011-08-10 03:30:03', '2011-08-10 03:45:03', '2011-08-10 04:00:03', '2011-08-10 04:15:01',
Any Help WOuld be greatly appreciated! Ive been tinking around with this for hours.
try date()
or use DATE_FORMAT() directly in MYSQL query:
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-format