David David - 4 months ago 6
PHP Question

Output timestamp format in PHP script, month written in words in another language

The timestamp in my MySQL database looks like this:

2016-06-05 13:33:39

How can I output this in PHP this way:
5. Juni

I only want to output the day and the month. I want to have the month in words, in German language.

I have already googled, but that didn't help me. Does anybody know how to do this?


This should work, but make sure the right language is installed on your server. On a unix system you could check this by entering the following in your terminal:

locale -a

If de_DE.UTF-8 is mentioned in the list, the code below should work for you.

setlocale(LC_ALL, "de_DE.UTF-8");
$date = strtotime("2016-03-05 13:33:39"); // just as an example. $date should be the timestamp returned from your database
echo gmstrftime("%d %B %Y %H:%M:%S", $date); // 05 März 2016 13:33:39
echo strftime("%d %B %Y %H:%M:%S", $date); // 05 März 2016 13:33:39

So both strftime and gmstrftime will work. An important thing to mention is that gmstrftime returns the data as GMT whereas strftime uses the local settings to display the date and time.

strftime will be the better choice I guess, since it uses the local settings on your system.