This topic is locked
[SOLVED]

 Date format / wrong locale

7/23/2008 10:02:14 PM
PHPRunner General questions
Z
zeitsprung author

Since I'm playing around with the standard templates to learn more, I came across a problem which I couldn't solve yet...:
Using NEWS template, there is the following code in ListOnLoad event page

function ListOnLoad(&$params)

{global $smarty;

$datetop = date("l, d F, Y");

$smarty->assign("datetop",$datetop);

}



The corresponding tag in the template (main_list.htm) is 'some text {$datetop}' - but contrary to the language settings (German/German in my case) in PHPR, the date is displayed in English.

Is there a way to change this date format corresponding to the language set in PHPR? All other date formats (on add/edit pages) display the months and days in correct language as stored in 'locale.php'.

Thanks.

J
Jane 7/24/2008

Hi,
try to use this code:

global $smarty;

if ($_SESSION["language"]=="English")

$datetop = date("l, d F, Y");

if ($_SESSION["language"]=="French")

$datetop = date("l jS \of F Y h:i:s A");

$smarty->assign("datetop",$datetop);

Z
zeitsprung author 7/24/2008

Hi Jane,

thanks for your suggestion

global $smarty;

if ($_SESSION["language"]=="English")

$datetop = date("l, d F, Y");

if ($_SESSION["language"]=="French")

$datetop = date("l jS \of F Y h:i:s A");

$smarty->assign("datetop",$datetop);



Sorry, but this solution works only in multi-language environment since $_SESSION["language"] remains empty when in single-language mode. Regardless which mode or which language is selected, the display of this date remains in English (others display correct).

I did build the files in multi-language mode and switching languages works perfectly - except the date mentioned. Is there an easy workable solution for this issue? Just curious...

Thanks.

J
Jane 7/25/2008

Hi,
you can change date format as you want.

If you use single-language mode just edit date format in the date() function:

$datetop = date("l, d F, Y");

Z
zeitsprung author 7/25/2008

you can change date format as you want.



Obvious, alas you seem to misunderstand me a second time. Regardless which language and date format is used in this place, date is displayed as e.g. Friday, July 25 2008 - but should be 'Vendredi, Juillet 25 2008' in French.

I hope that it is clear now, what I mean. This only happens at this particular location.

J
Jane 7/25/2008

Hi,
date() function returns all months in english only:

http://php.net/manual/en/function.date.php
If you want to contruct full date with french name use your own custom code.

Here is just a sample:

if (date("n")==1)

$month = "Janvier";

if (date("N")==5)

$day = "Vendredi";

...

$datetop = $day.",".$month." ".date("j")." ".date("Y");

Z
zeitsprung author 7/25/2008

date() function returns all months in english only:



Ah, this helped a lot. Guess I have much to read in future <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=31423&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />

Thank you