How to alter American format dates and / m / d for d / m / y?

4

I bought some systems but all of them come with date fields in English, as well as the American standard: year / month / day.

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

    
asked by anonymous 15.07.2014 / 23:50

4 answers

10
<?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 to search the files, so you search where you have date, date, $ date something like this until you find and use the second option you convert to our most common format

    
16.07.2014 / 02:35
3

Maybe you can use locale . Here's 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:

16.07.2014 / 02:12
3

You can use a set of functions as follows:
Moving from the American format to the Brazilian format:

implode('/', array_reverse(explode('-', $data)));

E Moving from the Brazilian format to the American format:

implode('-', array_reverse(explode('/', $data)));

Links:
explode (): link
implode (): link
array_reverse (): link

    
17.07.2014 / 15:28
1

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

See 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
    
17.07.2014 / 14:26