Get day from string in spanish php

I'm trying to:

setlocale(LC_ALL,"es_ES"); $string = "24/11/2014"; $date = DateTime::createFromFormat("d/m/Y", $string); echo $date->format("l"); 

And I get Monday, that's right, but I need it in Spanish, so is there any way to get this day in Spanish?

+8
date php localization
source share
4 answers

On a DateTime format page:

This method does not use locales. All products are in English.

If you need locales, look at strftime Example:

 setlocale(LC_ALL,"es_ES"); $string = "24/11/2014"; $date = DateTime::createFromFormat("d/m/Y", $string); echo strftime("%A",$date->getTimestamp()); 
+13
source share

using

 set_locale(LC_ALL,"es_ES@euro","es_ES","esp"); echo strftime("%A %d de %B del %Y"); 

or

 function SpanishDate($FechaStamp) { $ano = date('Y',$FechaStamp); $mes = date('n',$FechaStamp); $dia = date('d',$FechaStamp); $diasemana = date('w',$FechaStamp); $diassemanaN= array("Domingo","Lunes","Martes","Miércoles", "Jueves","Viernes","Sábado"); $mesesN=array(1=>"Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio", "Agosto","Septiembre","Octubre","Noviembre","Diciembre"); return $diassemanaN[$diasemana].", $dia de ". $mesesN[$mes] ." de $ano"; } 
+2
source share

I use:

 setlocale(LC_ALL, "es_ES", 'Spanish_Spain', 'Spanish'); echo iconv('ISO-8859-2', 'UTF-8', strftime("%A, %d de %B de %Y", strtotime($row['date']))); 

or

 setlocale(LC_ALL,"es_ES@euro","es_ES","esp"); 

both work. I have to use iconv to avoid weird characters in accents, and I get this result:

 domingo, 09 de octubre de 2016 
+2
source share

Here is how I did it.

 // Define key-value array $days_dias = array( 'Monday'=>'Lunes', 'Tuesday'=>'Martes', 'Wednesday'=>'Miércoles', 'Thursday'=>'Jueves', 'Friday'=>'Viernes', 'Saturday'=>'Sábado', 'Sunday'=>'Domingo' ); //lookup dia based on day name $dia = $days_dias[date('l', strtotime("1993-04-28"))]; 
0
source share

All Articles