how to display and translate current date and time?
vthirteen - January 5, 2008 - 02:26
i know that current date can be easily disaplyed through php with print date, e.g.:
<?php
print date('l j F Y')
?>but in this way i can't get the string translated.
what's the best way to get current date translated?

...
Instead, use Drupal's format_date():
<?phpprint format_date(time(), 'custom', 'l j F Y');
?>
thank you!
thank you!
custom language
Hello,
I have a custom language because I do not want the admin tools translated. I am trying to translate the date string, so I used your suggestion above and I'm setting the string:
$date_string = t('%date', array('%date' => format_date($timestamp, 'custom', 'l, F j')));I also translated all days and months in my .po file. This is working so that "Tuesday, April 22" is now translated to "Martes, Abril 22". However this is not the correct format... how would I translate it to "Martes, 22 de Abril" ?
...
Change
l, F jtol, j \d\e F(See the table at http://php.net/date for the meaning of each letter.)
But do I put that in the .po
But do I put that in the .po file? I don't want "de" to display in English... so if I made that change in the module won't it display that way in English also? I only want to change it to that format for my custom language.
...
You want to change the way a date is displayed.
What date?
Of a certain module? That is, in a very specific place?
Or... the dates throughout Drupal?
Your question isn't clear. You're mentioning some details, some 'po', some mysterious 'module', but you aren't explaining, in general, what you're trying to achieve.
You're so right, I'm sorry!
You're so right, I'm sorry! I really appreciate your help!
I have a custom module that creates a calendar block, displaying a highlighted event for each day of the week. The block displays the date string for each day as "Day, Month number (Wednesday, April 23)". You can view it here http://www.miami.com in the left rail. Now we are creating this site in Spanish, so I need to use this same module, but translate it into Spanish. We're not using the spanish translation file because our developers do not speak spanish so we want the admin tools in English. So we created a new language and .po file to only translate what our users will see.
So in our module we are setting the date string here:
$date_string = t('%date', array('%date' => format_date($timestamp, 'custom', 'l, F j')));I want to translate this specific date string (but the module creates a string for each day of the week). So in our translation file mia.po for our spanish site we have translated all days and months to their spanish values. So the translation is working now... on our spanish site you see "Miercoles, Abril 23", "Jueves, Abril 24" ... However, this is not the correct format for spanish dates... it should be "Miercoles, 23 de Abril". So I'm not sure how to change the format only for our spanish site.
...
I see.
You now have:
$date_string = ... 'l, F j' ...Change it to:
$date_string = ... t('l, F j') ...This will make the string 'l, F j' itself translatable. In your spanish 'po' simply translate it to 'l, j \d\e F'.
====
There's another approach: Make your module have a settings page, and in it provide a textfield in which the admin will be able to type a date format string. I think this is a better solution, because even 'English' sites may want to change the way dates are displayed. It's more a matter of preferences than of language.
====
If you're lazy, you don't even have to go all the way of programming a settings page. You can do without. Change:
$date_string = ... 'l, F j' ...to:
$date_string = ... variable_get('mymodule_dateformat', 'l, F j') ...This is enough to make the date display configurable. If I wanted, on my site, to display dates as '2008-06-24', I'd add the following to my 'settings.php':
$conf['mymodule_dateformat'] ='Y-m-d';(But, because there's no settings page, you'll have to document this feature in your README or else admins won't know about it.)
Thank you!
I didn't realize I could wrap the date format in the translate function... makes perfect sense :) I tried that initially but I was getting "Jueves, 24 24e Abril". I'm sure I could've figured it out, but you were right about the settings page so I decided to go that way. That worked great!
I really appreciate your help, thank you so much!