Displaying a date in question text, according to user-selected language

More
3 years 3 months ago - 3 years 3 months ago #119989 by eirikat
eirikat created the topic: Displaying a date in question text, according to user-selected language
Hi,

I'm developing a survey in several languages, and would like to include today's date in one of the questions. Currently, I do this using Expression Manager:
{date("l F n\t\h, o")} // Output: Tuesday May 5th, 2015

However, this way of formatting the date has several shortcomings:
  • The "th" doesn't work for the first, second and third of each month
  • For other languages than English, the format is inappropriate. For example, in Norwegian, I would have liked to write "Tirsdag 5. mai, 2015", which requires setting the nb_NO locale. Somehow, this is not achieved by changing the survey language. In fact, not even the survey's standard language affects this (standard language is set to Norwegian, but English is displayed).
Is there a way of linking the locale used for formatting dates in a question, to the language selected by the survey respondent? And, subsequently, how might I include special cases to present dates like 1st, 2nd and 3rd?

Thanks in advance for your help!
Last Edit: 3 years 3 months ago by eirikat. Reason: Text formatting

Please Log in or Create an account to join the conversation.

More
3 years 3 months ago #120155 by jazzy
jazzy replied the topic: Displaying a date in question text, according to user-selected language
I think what you are looking for is

{date("l F jS, o")}

j = Day of the month without leading zeros
S = English ordinal suffix for the day of the month, 2 characters

As far as the language question I'm just guessing here but these functions are not Lime Survey functions but PHP functions. As such, I doubt you can change it by changing any settings in limesurvey.

Cheers,
Jeff
The following user(s) said Thank You: eirikat

Please Log in or Create an account to join the conversation.

More
3 years 3 months ago #120233 by eirikat
eirikat replied the topic: Displaying a date in question text, according to user-selected language
Thank you, jazzy, this works perfectly in English. I think you are right about the language settings for time being set in PHP somewhere. I'll see if I can figure out a workaround.

Cheers,

Eirik

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!