Convert date format to php echo

Asked

Viewed 763 times

1

Good afternoon,

My database is saving dates in the following format "2017-04-19", I do not know if it has to change the data already registered in it and the way the data will be saved, so I chose to treat the date in my php code, which I have not been successful, my echo today is as follows:

   echo '<td>' . $row['data_chamada'] . '</td>';

What would be the correct syntax to transform the date format to the one used here in Brazil(DD/MM/YYYY)?

1 answer

1

You can use

    date_format($row['data_chamada'],"d/m/Y");
  • I even understand the logic involved, but I could not apply in my code, as would echo in this case?

  • echo '<td>' . date_format($Row['data_call'],"d/m/Y") . '</td>';

  • It was exactly what I tried but the result was blank, until I thought it was me who was not knowing to apply.

  • In this case the error may occur due to $Row['data_call'] is not in format Date use DATE_FORMAT(field,'%d-%m-%Y') in your sql query using so you do not need to use date formatted in php echo example: $sql = "SELECT DATE_FORMAT(date,'%d-%m-%Y') PRODUCTS" in this case your php code will look like echo '<td>' . $Row['call date'] . '</td>';

  • Got it, my current SELECT is down, is there any way to adapt it or do I need to find a way to make a new one? $sql = mysql_query('SELECT * FROM coleta_hc_2017 ORDER BY id DESC LIMIT 100');

  • You can tailor your query by placing the fields to be filtered by SELECT using date_format to format the Date, or you can take the result of the query and turn it into a date like $date=date_create($Row['data_call']); and apply the first solution echo '<td>' . date_format($Row['data_call'],"d/m/Y") . '</td>';

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.