How to change dates from the American format y/m/d to d/m/y?

Asked

Viewed 29,756 times

4

I bought some systems but all come with date fields in English, and also in American standard: year/month/day.

How do I convert to day/month/year format?

  • 5

    And this date is where? In the database? In the PHP file?

  • 4

    Anthony, Welcome to Stackoverflow. You can explain your question better and be clearer on what you’re looking for. I understand you want to convert the date format but I have no idea where you want to do it...

  • 2

    If you can post the code and the database helps a lot, read the [Ask] tab and then [Edit] and your question.

  • He wants to convert the format in PHP, to reply is that the AP intends.

  • Be careful, if you have any connection to a database like Mysql, you should do all the Inserts in American format.

4 answers

12

<?php
echo date('Y/m/d'); // retorna a data nesse formato ano/mês/dia, essa data é a atual do servidor você pode alterar da forma que desejar exemplo date('d-m-Y')

echo date('d/m/Y',  strtotime($variavel)); // convert a data da $variavel para o formato dia/mês/ano
?>

I advise you to use notepadd++ or Dreamweaver the resource to search in the files, so you search where you have date, date, $date something like that until you find and use the second option that Convert to our most common format

3

3

Maybe you can use the locale. Take an example:

<?php
/* Define o local para Holandês(usar pt_BR para o Português(Brasil) ) */
setlocale (LC_ALL, 'nl_NL');

/* Mostra: vrijdag 22 december 1978 */
echo strftime ("%A %e %B %Y", mktime (0, 0, 0, 12, 22, 1978));

/* Tenta diferentes nomes de local para o Alemão apartir do PHP 4.3.0 */
$loc_de = setlocale (LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');
echo "Preferred locale for german on this system is '$loc_de'";
?>

References:

1

To convert dates from any format that date, you can use the native PHP Datetime class.

Take an example:

<?php
 $data = '2014/07/17';
 $data_brasil = DateTime::createFromFormat('Y/m/d', $data);

 print_r($data_brasil->format('d/m/Y')); //17/07/2014

Browser other questions tagged

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