PHP - Multiple Format Date Spanish


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. #Example:
  2. get_date_spanish(time(), true, 'month'); # return Enero
  3. get_date_spanish(time(), true, 'month_mini'); # return ENE
  4. get_date_spanish(time(), true, 'Y'); # return 2007
  5. get_date_spanish(time());#return 06 de septiempre, 12:31 hs
  6.  
  7.  
  8.  
  9. #Power by nicolaspar 2007 - especific proyect
  10. function get_date_spanish( $time, $part = false, $formatDate = '' ){
  11. #Declare n compatible arrays
  12. $month = array("","enero", "febrero", "marzo", "abril", "mayo", "junio", "julio", "agosto", "septiempre", "diciembre");#n
  13. $month_execute = "n"; #format for array month
  14.  
  15. $month_mini = array("","ENE", "FEB", "MAR", "ABR", "MAY", "JUN", "JUL", "AGO", "SEP", "DIC");#n
  16. $month_mini_execute = "n"; #format for array month
  17.  
  18. $day = array("domingo","lunes","martes","miércoles","jueves","viernes","sábado"); #w
  19. $day_execute = "w";
  20.  
  21. $day_mini = array("DOM","LUN","MAR","MIE","JUE","VIE","SAB"); #w
  22. $day_mini_execute = "w";
  23.  
  24. /*
  25. Other examples:
  26.   Whether it's a leap year
  27.   $leapyear = array("Este año febrero tendrá 28 días"."Si, estamos en un año bisiesto, un día más para trabajar!"); #l
  28.   $leapyear_execute = "L";
  29. */
  30.  
  31. #Content array exception print "HOY", position content the name array. Duplicate value and key for optimization in comparative
  32. $print_hoy = array("month"=>"month", "month_mini"=>"month_mini");
  33.  
  34. if( $part === false ){
  35. return date("d", $time) . " de " . $month[date("n",$time)] . ", ". date("H:i",$time) ." hs";
  36. }elseif( $part === true ){
  37. if( ! empty( $print_hoy[$formatDate] ) && date("d-m-Y", $time ) == date("d-m-Y") ) return "HOY"; #Exception HOY
  38. if( ! empty( ${$formatDate} ) && !empty( ${$formatDate}[date(${$formatDate.'_execute'},$time)] ) ) return ${$formatDate}[date(${$formatDate.'_execute'},$time)];
  39. else return date($formatDate, $time);
  40. }else{
  41. return date("d-m-Y H:i", $time);
  42. }
  43. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.