Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get day from string in spanish PHP

I'm trying with:

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

And I'm getting Monday, which is correct but I need it in spanish, so, is there any way to retrieve this day in spanish?

like image 593
Mark Avatar asked Mar 25 '14 12:03

Mark


People also ask

What is strtotime()?

The strtotime() function parses an English textual datetime into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT). Note: If the year is specified in a two-digit format, values between 0-69 are mapped to 2000-2069 and values between 70-100 are mapped to 1970-2000.

How to convert string to time in PHP?

The strtotime() function is a built-in function in PHP which is used to convert an English textual date-time description to a UNIX timestamp. The function accepts a string parameter in English which represents the description of date-time. For e.g., “now” refers to the current date in English date-time description.

How to get timestamp in PHP?

The time() function returns the current time in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).


1 Answers

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());
like image 88
Jim Avatar answered Sep 21 '22 04:09

Jim