Skip to content

Instantly share code, notes, and snippets.

@ivanmendoza
Created February 21, 2012 18:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ivanmendoza/1878065 to your computer and use it in GitHub Desktop.
Save ivanmendoza/1878065 to your computer and use it in GitHub Desktop.
Get relative date (spanish)
// 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 ".$inHours." d&iacute;as";}
// OUTPUT: $txt_date
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment