php - How to change date language?

<table >
  <tr><td colspan="2">Vergangene Projekte</td></tr>

<?php  $query = "SELECT * FROM posts WHERE project = 1 && project_date <= CAST(CURRENT_TIMESTAMP AS DATE)ORDER BY date DESC";
    die("Konnte nicht mit Data Base verbinden");}
    $result = mysqli_query($connection, $query);

while($row = mysqli_fetch_array($result)){

    setlocale(LC_ALL, 'de_DE'); // using german language works
    $premier = new DateTime($row['project_date']);
    echo "<tr><td>" .strftime("%B", $premier->getTimestamp()). "</td><td class=\"project_title\">
    <a class=\"title\" href=\"projekt_info.php?projekt=" .urlencode($row["id"]) ."\">" 
    .$row['title']. "</a></td></tr>";} 

Ok I modified the code to show all of it and also inserted the suggestions and now it works just fine!! Perfect

Cheers Chris




First off make sure that indeedfr_FR is installed on the machine for your script to use.

Try to uselocale -a on your terminal to check.

Second, sinceDateTime only works on english, usestrftime() on that, and you're using it without the timestamp.

setlocale(LC_ALL, 'fr_FR');
$premier = new DateTime($row['project_date']);
echo "<tr><td>" .strftime("%B", $premier->getTimestamp()). "</td><tr>";
                                   // ^^ feed the timestamp

Sidenote: as Fred said in the comments, this is just a fragment because your markup is a bit off (missing tags, etc, and most likely this is inside a loop).




A bit late but I prefer using IntlDateFormatter which is system-locale independant and output is guaranteed to be in UTF-8:

$datefmt = new IntlDateFormatter('de_DE', NULL, NULL, NULL, NULL, 'LLLL');
while($row = mysqli_fetch_array($result)) {
    # ...
    echo "<tr><td>" . $datefmt->format($premier). "</td>"/*...*/;
    # ...

(see ICU's documentation for a custom format - the last argument of IntlDateFormatter constructor)

People are also looking for solutions to the problem: php - Wordpress Contact form 7 error while mail recieving


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.