views:

19

answers:

2

I have a column which is a Timestamp.

It records something like: 2010-02-08 12:10:22

Then I use this in php:

 $postdate = date( "j F", strtotime( $row['modify_date'] ) );

And it can output something like: 8 February

My Q is, how can I change the date-text so it outputs the month name in another language (swedish specifically)?

Ex: January is in Swedish Januari

Thanks

+1  A: 

If you use setlocale() then you can output locale-specific names via strftime().

Ignacio Vazquez-Abrams
+2  A: 

The native PHP function for that is strftime().

%B Full month name, based on the locale January through December

if the server is not in the swedish locale, use setlocale().

That said, I have had so many troubles with setlocale() in the past, especially on shared hosting, that I tend to keep an array of month names in whatever config file / dictionary file the project has:

$monthnames["de"] = array("Januar", "Februar", "März", "...");
$monthnames["fi"] = array("Tammikuu", "Helmikuu", "...");


echo $monthnames[$language][date("n", strtotime( $row['modify_date'] ))]; 
Pekka
How can I set the local time on my virtual server then? Whats the var name?
Camran
What do you mean by local time? The server clock?
Pekka
No sorry, I thought by setting the "lc_time_names" to sv_SE it would change all dates to the swedish language. but didn't work :(. I am managing a VPS so I can set whatever variables I like, that's what I meant... hmmmm Maybe I will go with the array then, it's only 12 values anyways.
Camran
If you ask me, go with the array. The correct locale could be anything - `sv_se`, `sv_SE`, `se_SV` (who knows?), `SV`, `sv`, `se_se`? maybe `sv_SE-UTF8`? I'm exaggerating but there's more than a little truth to it.
Pekka
FYI. You left out a quote-mark in the code. Messes up the highlighting :)
Atli
Cheers @Atli, I was wondering why it's messed up!
Pekka