-
-
Save lpirir/1886170 to your computer and use it in GitHub Desktop.
Get relative date (spanish)
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
// INPUT: $item_date | |
$item_date = date("D, d M o G:i:s T",strtotime($item_date)); | |
$today = date(DATE_RFC822); | |
$diff_date=(strtotime($today) - strtotime($item_date)); | |
$inMinutes=round($diff_date/60); | |
$inHours=round($diff_date/(60*60)); | |
$inDays=round($diff_date/(24*60*60)); | |
if($inMinutes==1){$txt_date="hace un minuto";} | |
else if($inMinutes<60){$txt_date="hace ".$inMinutes." m.";} | |
else if($inHours==1){$txt_date="hace una hora";} | |
else if($inHours<12){$txt_date="hace ".$inHours." horas";} | |
else if($inHours<24){$txt_date="es de hoy";} | |
else if($inDays<48){$txt_date="es de ayer";} | |
else if($inDays>2){$txt_date="hace ".$inDays." días";} | |
// OUTPUT: $txt_date |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment