Question

On our store we have a blog where we show the "created_at" date of the entity. But we show the same post to 5 different languages. Of course the content is translated but we don't know how we should translate the date.

Currently we display it like this:

$date = date("d F, Y", strtotime($date)); // $date = 2019-04-16 08:45:25
echo "<span> " . $date . "</span>";

This outputs something like this:

enter image description here

Our main problem here is that the month is in english in all our languages. Is there a way to translate just the month?

PS: According to our PM just using the month number is not an option.

Was it helpful?

Solution

To format dates in other languages, you should use the setlocale() and strftime() functions.

<?php
setlocale(LC_TIME, "fr_FR"); // Here fr_FR is your translation locale
echo strftime("%d %B, %Y");
?>

Hope it finds helpful.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top