Last active
October 13, 2021 11:02
-
-
Save helisoncruz/29f01ec8ad2f1f0ca66904a6395cb083 to your computer and use it in GitHub Desktop.
Calcula Tempo
This file contains hidden or 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
public function calculaTempo($data) | |
{ | |
$mydate = date("Y-m-d H:i:s"); | |
$datetime1 = date_create($data); | |
$datetime2 = date_create($mydate); | |
$interval = date_diff($datetime1, $datetime2); | |
$min = $interval->format('%i'); | |
$sec = $interval->format('%s'); | |
$hour = $interval->format('%h'); | |
$mon = $interval->format('%m'); | |
$day = $interval->format('%d'); | |
$year = $interval->format('%y'); | |
if ($interval->format('%i%h%d%m%y') == "00000") { | |
return $sec . " Segundos atrás"; | |
} else if ($interval->format('%h%d%m%y') == "0000") { | |
return $min . " Minutos atrás"; | |
} else if ($interval->format('%d%m%y') == "000") { | |
return $hour . " Horas atrás"; | |
} else if ($interval->format('%m%y') == "00") { | |
return $day . " Dias atrás"; | |
} else if ($interval->format('%y') == "0") { | |
return $mon . " Meses atrás"; | |
} else { | |
return $year . " Anos atrás"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment