0

I have the following select statement.

$sql = "SELECT *, DATE_FORMAT(date, '%d-%m-%Y') FROM alerts"; 

I use the following PHP code to echo

 echo "" . $row["date"].""; 

No matter what I do I receive Year-Month-Day instead of Day-Month-Year. Any ideas?

1
  • 1
    is your variable in mysql of date format? Commented Jul 16, 2015 at 18:10

1 Answer 1

2

Your problem is that you don't alias the formatted date in SQL, so the date field from your select is still the same.

Either alias the formatted date and output on that,

$sql = "SELECT *, DATE_FORMAT(date, '%d-%m-%Y') AS formattedDate FROM alerts"; // ... echo $row['formattedDate']; 

Or you can format the date in PHP,

$sql = "SELECT * FROM alerts"; // ... echo date("d-m-Y", strtotime($row['formattedDate'])); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.