Created
October 30, 2015 03:21
-
-
Save victorvaz/a1e7a4b0b41586147a34 to your computer and use it in GitHub Desktop.
Formatando uma data utilizando a função date() do PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Formatação de datas usando a função date: | |
$dataNormal = "2015-01-07"; | |
$dataConvertida = date("d/m/Y", strtotime($dataNormal)); | |
print $dataConvertida; // 07/01/2015 | |
$dataNormal = "07/01/2015"; | |
//Obs.: É necessário substituir a barra por traço | |
$dataConvertida = date("Y-m-d", strtotime(str_replace("/", '-', $dataNormal))); | |
print $dataConvertida; // 2015-01-07 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment