0

Im trying to get my date out of the DB in duth. Im spliting the date into seperate month, day and year variables and changed the month number to text but now i need to get in into dutch instead of english. I found some information on SO about it like setlocale(LC_ALL, 'nl_NL') but i cant get it to work.

<?php

      include_once("db/db.php");
      $statement = $db_con->prepare("select * from news_article where id > :id");
        $statement->execute(array(':id' => 0));
      $list = $statement->fetchAll(PDO::FETCH_ASSOC);
    ?>    
<?php
    foreach($list as $col)
    {
      // splitting into seperate month day year
      $orderdate = explode('-', $col['datum']);
      $year = $orderdate[0];
      $month   = $orderdate[1];
      $day = $orderdate[2];

      $dateObj   = DateTime::createFromFormat('!m', $month);
      $monthName =
      $dateObj->format('F');


      ?>
//this needs to output in dutch
<p class="month"><?php echo $monthName  ?></p>
Heis
  • 606
  • 5
  • 25
  • have a look at http://stackoverflow.com/questions/13845554/php-date-get-name-of-the-months-in-local-language – Chetan Ameta Apr 11 '17 at 09:09
  • DateTime::format() is not aware of locales (http://php.net/manual/en/datetime.format.php#refsect1-datetime.format-notes), use strftime() instead – Oliver Hader Apr 11 '17 at 09:45

1 Answers1

1
<?php
$f = date('F');
    function dutch_format($value) {

        $months = array(
            "January"   => "januari",
            "February"  => "februari",
            "March" => "maart",
            "April"     => "april",
            "May"       => "mei",
            "June"      => "juni",
            "July"      => "Juli",
            "August"    => "augustus",
            "September" => "september",
            "October"   => "oktober",
            "November"  => "november",
            "December"  => "december"
        );

        return $months[$value];
    }
    echo $f;
    echo "<br/>";
    echo dutch_format($f);
?>

It will return DUTCH format. Guide me if I did any mistake

Siddhartha esunuri
  • 1,104
  • 1
  • 17
  • 29
  • Please consider using `strftime` and locales for that. If you have to maintain a system with 50 languages, your solution might be quite unhandy... – Oliver Hader Apr 11 '17 at 09:47