Reputation: 1
I am trying to display a graph using Highcharts to display one column of data from our db. In our db the date format is yyyy-mm-dd, but Highcharts requires dd-mm-yyyy. I want to be able to wite php code to download the data to a .csv that will display it in the correct data format for Highcharts. I have done some looking around and I found that I can format the date from the db, but I must not be implementing the DATE_FORMAT correctly. Be kind, I am a noob to php and Mysql!
Original
$result = mysql_query("SELECT date, data
FROM mytablename
ORDER BY date ") or die(mysql_error());
Failed date format
$result = mysql_query("SELECT DATE_FORMAT(date,'%m-%d-%Y'), data
FROM mytablename
ORDER BY date ") or die(mysql_error());
Upvotes: 0
Views: 1808
Reputation: 95243
Try this:
$result = mysql_query("SELECT DATE_FORMAT(date,'%d-%m-%Y') as `date`, data
FROM mytablename
ORDER BY date ") or die(mysql_error());
You're formatting your date incorrectly as mm-dd-yyyy
, and you're not aliasing your column as date
.
Upvotes: 1