Ver Mensaje Individual
  #2 (permalink)  
Antiguo 21/01/2018, 14:11
Avatar de xfxstudios
xfxstudios
 
Fecha de Ingreso: junio-2015
Ubicación: Valencia - Venezuela
Mensajes: 2.448
Antigüedad: 8 años, 9 meses
Puntos: 263
Respuesta: automatizar formato de fecha

Prueba este:
Código PHP:
Ver original
  1. function Hace($X){
  2.         $lan = "es";
  3.         $data = array(
  4.             'es'=>array('HSEGUNDOS'=>'Hace segundos','HMINUTO'=>'Hace un minuto','HMINUTOS'=>'Hace %min% minutos','HHORA'=>'Hace una hora','HHORAS'=>'Hace %hor% horas','HDIA'=>'Hace un día','HDIAS'=>'Hace %dia% días','HSEMANA'=>'Hace una semana','HSEMANAS'=>'Hace %sem% semanas','HMES'=>'Hace un mes','HMESES'=>'Hace %mes% meses','HANO'=>'Hace un año','HANOS'=>'Hace %ano% años'),
  5.  
  6.             'en'=>array('es'=>array('HSEGUNDOS'=>'Second ago','HMINUTO'=>'Minute ago','HMINUTOS'=>'Minutes %min% ago','HHORA'=>'One hour ago','HHORAS'=>' %hor% hours ago','HDIA'=>'A day ago','HDIAS'=>'%dia% days ago','HSEMANA'=>'A week ago','HSEMANAS'=>'%sem% weeks ago','HMES'=>'A month ago','HMESES'=>'%mes% months ago','HANO'=>'A year ago','HANOS'=>'%ano% years ago'),)
  7.             );
  8.  
  9.             $fecha = strtotime($X);
  10.  
  11.                 $diferencia = time() - $fecha ;
  12.                 $segundos   = $diferencia ;
  13.                 $minutos    = round($diferencia / 60 );
  14.                 $horas      = round($diferencia / 3600 );
  15.                 $dias       = round($diferencia / 86400 );
  16.                 $semanas    = round($diferencia / 604800 );
  17.                 $mes        = round($diferencia / 2419200 );
  18.                 $anio       = round($diferencia / 29030400 );
  19.  
  20.                 if($segundos <= 60){
  21.                     return $data[$lan]['HSEGUNDOS'];
  22.  
  23.                 }else if($minutos <= 60){
  24.  
  25.                     if($minutos==1){
  26.                         return $data[$lan]['HMINUTO'];
  27.                     }else{
  28.                         return str_replace("%min%",$minutos,$data[$lan]['HMINUTOS']);
  29.                     }
  30.                 }else if($horas <=24){
  31.  
  32.                     if($horas==1){
  33.                         return $data[$lan]['HHORA'];
  34.                     }else{
  35.                         return str_replace("%hor%",$horas,$data[$lan]['HHORAS']);
  36.                     }
  37.                 }else if($dias <= 7){
  38.                     if($dias==1){
  39.  
  40.                         return $data[$lan]['HDIA'];
  41.                     }else{
  42.                         return str_replace("%dia%",$dias,$data[$lan]['HDIAS']);
  43.                     }
  44.                 }else if($semanas <= 4){
  45.                     if($semanas==1){
  46.                         return $data[$lan]['HSEMANA'];
  47.                     }else{
  48.                         return str_replace("%sem%",$semanas,$data[$lan]['HSEMANAS']);
  49.                     }
  50.                 }else if($mes <=12){
  51.                     if($mes==1){
  52.                         return $data[$lan]['HMES'];
  53.                     }else{
  54.                         return str_replace("%mes%",$mes,$data[$lan]['HMESES']);
  55.                     }
  56.                 }else{
  57.                     if($anio==1){
  58.                         return $data[$lan]['HANO'];
  59.                     }else{
  60.                         return str_replace("%ano%",$anio,$data[$lan]['HANOS']);
  61.                     }
  62.                 }
  63.     }//fin function Hace
  64.  
  65. echo Hace("2018-1-15");

MUESTRA
__________________
[email protected]
HITCEL