-1

i want to echo cMonth in spanish.. i was trying differents things without result. any idea?

if($_REQUEST["month"]>0){
    $cMonth = "0".intval($_REQUEST["month"]);
    if ($_REQUEST["month"]>9) {
        $cMonth = intval($_REQUEST["month"]);
    }
    $cYear = intval($_REQUEST["year"]);
}else
{
    $cMonth = date("m");
    $cYear = date("Y");
}

echo date("F, Y",strtotime($cYear."-".$cMonth."-01")); 
yivi
  • 42,438
  • 18
  • 116
  • 138
CosmicDisco
  • 21
  • 1
  • 4
  • Use strftime (http://php.net/strftime) instead of "date". Look this answer: http://stackoverflow.com/questions/4975854/translating-php-date-for-multilingual-site – yivi Dec 26 '16 at 16:56

1 Answers1

1

Hi You can use this methode Just

    setlocale(LC_ALL, "es_ES", 'Spanish_Spain', 'Spanish');
    $string = "27/12/2016";
    $date = \DateTime::createFromFormat("d/m/Y", $string);
    echo strftime("%B", $date->getTimestamp());
Barkati.med
  • 620
  • 5
  • 11
  • thanks!! but i dont know well how integrated here: date("F, Y",strtotime($cYear."-".$cMonth."-01")); – CosmicDisco Dec 26 '16 at 17:24
  • I don't understand what is the problem – Barkati.med Dec 26 '16 at 17:43
  • @CosmicDisco, I guess you want see in this format "F, Y" but using strftime. You could check [strftime documentation](https://secure.php.net/manual/pt_BR/function.strftime.php). – Vinícius Fagundes Dec 26 '16 at 19:17
  • the problem is i want the months in spanish.. when i try to modify strtotime for strftime doesnt work. i dont know how to modify this: date("F, Y",strtotime($cYear."-".$cMonth."-01")); – CosmicDisco Dec 27 '16 at 00:01
  • Try To Modifier your echo date("F, Y", strtotime($cYear . "-" . $cMonth . "-01")); by setlocale(LC_ALL, "es_ES", 'Spanish_Spain', 'Spanish'); $string = $cYear . "/" . $cMonth . "/01"; $date = \DateTime::createFromFormat("Y/m/d", $string); echo strftime("%B, %Y", $date->getTimestamp()); The Out Put Its Like What you want – Barkati.med Dec 27 '16 at 09:44