output a date in other language than English

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sofasurfer
Forum Newbie
Posts: 3
Joined: Mon Jun 20, 2005 3:42 pm
Location: porto

output a date in other language than English

Post by sofasurfer »

hello!

I need to uotput a date field from my database (aaaa/mm/dd) in Portuguese on the following manner: Month Year.
already can output that in Inglish, for instance May 2005 with date_format in the sql query.

now, how can I output it in Portuguese?
I tried setlocale and strtime but isn't working

Code: Select all

<?php setlocale(LC_ALL, 'pt_PT.ISO8859-1', 'pt_PT.utf-8', 'portuguese', 'pt_PT');


and

Code: Select all

<? echo strftime($row_rsListaProvas['date_m']); ?><?php echo strftime($row_rsListaProvas['date_y']);
what i'm I doing wrong?

thx in advance! :D
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post by bokehman »

Hi! I did it manually rather than using the PHP built in functions. Anyway here goes:

Code: Select all

<?php 

$day = date ('w');
if ($day == '0') {
$day = 'Domingo';
}elseif ($day == '1') {
$day = 'Lunes';
}elseif ($day == '2') {
$day = 'Martes';
}elseif ($day == '3') {
$day = 'Miercoles';
}elseif ($day == '4') {
$day = 'Jueves';
}elseif ($day == '5') {
$day = 'Viernes';
}elseif ($day == '6') {
$day = 'Sábado';
}

$date = date ('j');

$month = date ('n');
if ($month == '1') {
$month = 'de enero de';
}elseif ($month == '2') {
$month = 'de febrero de';
}elseif ($month == '3') {
$month = 'de marzo de';
}elseif ($month == '4') {
$month = 'de abril de';
}elseif ($month == '5') {
$month = 'de mayo de';
}elseif ($month == '6') {
$month = 'de junio de';
}elseif ($month == '7') {
$month = 'de julio de';
}elseif ($month == '8') {
$month = 'de agosto de';
}elseif ($month == '9') {
$month = 'de septiembre de';
}elseif ($month == '10') {
$month = 'de octubre de';
}elseif ($month == '11') {
$month = 'de noviembre de';
}elseif ($month == '12') {
$month = 'de diciembre de';
}

$year = date ('Y');

print ("$day $date $month $year");
?>
Post Reply