I\'m trying with:
setlocale(LC_ALL,\"es_ES\");
$string = \"24/11/2014\";
$date = DateTime::createFromFormat(\"d/m/Y\", $string);
echo $date->format(\"
This 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"))];
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 works. I have to use iconv
to avoid strange symbols in accents, and i obtain this result:
domingo, 09 de octubre de 2016
From the DateTime format page:
This method does not use locales. All output is in English.
If you need locales look into strftime Example:
setlocale(LC_ALL,"es_ES");
$string = "24/11/2014";
$date = DateTime::createFromFormat("d/m/Y", $string);
echo strftime("%A",$date->getTimestamp());
use
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";
}