Created
March 10, 2012 04:59
-
-
Save jotapepinheiro/2010221 to your computer and use it in GitHub Desktop.
PHP - Transforma dias em data completa
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 | |
function timeToTexto($time){ | |
$retorno = array(); | |
$anos = floor($time/(86400*365)); | |
$time = $time%(86400*365); | |
$meses = floor($time/(86400*30)); | |
$time = $time%(86400*30); | |
$dias = floor($time/86400); | |
$time = $time%86400; | |
$horas = floor($time/(3600)); | |
$time = $time%3600; | |
$minutos = floor($time/60); | |
$segundos = $time%60; | |
if($anos>0) $retorno[] = $anos . ' ano' . ($anos > 1 ? 's' : ' '); | |
if($meses>0) $retorno[] = $meses . ' mes' . ($meses > 1 ? 'es' : ' '); | |
if($dias>0) $retorno[] = $dias . ' dia' . ($dias > 1 ? 's' : ' '); | |
if($horas>0) $retorno[] = $horas . ' hora' . ($horas > 1 ? 's' : ' '); | |
if($minutos>0) $retorno[] = $minutos . ' minuto' . ($minutos > 1 ? 's' : ' '); | |
if($segundos>0) $retorno[] = $segundos . ' segundo' . ($segundos > 1 ? 's' : ' '); | |
return implode(', ',$retorno); | |
} | |
$dias = 3526; | |
echo timeToTexto($dias*24*3600); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment