Date format within mysqli_query(

Hello all, I’m very new to using PHP and just need a little help with formating the date via MYSQL. Here is the code that I am getting an error on…

$result = mysqli_query($link, ‘SELECT id, name, rank, DATE_FORMAT(opened, ‘%d-%m-%Y’), active’);

Thank you for taking time to read my post and any suggestions would be greatly appreciated. --Ben

I thought that maybe I would clarify my post, I seem to get a lot views, but no replys yet.
If I use the following code, I get no error:

$result = mysqli_query($link, ‘SELECT id, name, rank, opened, active’);

And “opened” in MYSQL is a DATE column. The date that is displayed is YYYY-MM-DD. I was hoping to get the date to display as follows… d-m-Y.
When I use the following code, I get an error:

$result = mysqli_query($link, ‘SELECT id, name, rank, DATE_FORMAT(opened, ‘%d-%m-%Y’), active’);

I’m not sure if I’m using DATE_FORMAT incorectly or if there is another method? Thanks again for reading my post and any help/suggestions would be greatly appreciated. --Ben

i don’t do php and i figured a php developer would reply

but since no one did, i can tell you that your error is caused by your quotes

$result = mysqli_query($link, 'SELECT id, name, rank, DATE_FORMAT(opened, '%d-%m-%Y’), active’);

the quote for your date format string is terminating the mysqli_query parameter too soon

try swapping single for double quotes – i’d be more specific, but i don’t do php

r937,

Thank you very much for the suggestion, the cause made perfect sense in your post. I used double quotes in the date format and had to follow it with AS afterwards–it worked perfectly with no errors. Here is the final code…

$result = mysqli_query($link, ‘SELECT id, name, rank, DATE_FORMAT(opened, “%d-%m-%Y”) AS opened, active’);

Thank you. --Ben