Check out the LimeSurvey source code on GitHub!

add current month to var to re-use in multiple questions

More
2 years 10 months ago #106607 by Luneya
Hello LimeSurvey-Super Heroes!

I have been searching the forum for an answer as I was sure I couldn't be the only with this particular question. However, I have not been able to find the answer.

I want to display the current month in the text of multiple questions.
Just the month. Nothing more, nothing less.
Furthermore I would like to be able to display the 3rd month prior to the current month (example, the current month is March so I would like to be able to display January.)

Is there no simple way like in php to display the current month?

Cheers,

Leonie

Please Log in to join the conversation.

More
2 years 10 months ago - 2 years 10 months ago #106612 by tpartner
Expression Manager - manual.limesurvey.org/Expression_Manager .

Current month:
{date('F')}

Your example (March --> January) is actually the second previous month, not the third:
{date('F', strtotime("-2 months"))}


.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last Edit: 2 years 10 months ago by tpartner.
The following user(s) said Thank You: Luneya

Please Log in to join the conversation.

More
2 years 10 months ago #106615 by Luneya
Hi tpartner,

thank you for your reply. And you are indeed right, 3 months would make it December ;)

The {date('F')} works! I figured it would relay it back to me in the language the survey is set to, but this does not seem to be the case. How do I get it to display the month in Dutch, rather than English?

We have version 2.00+ (build 130526) and it does not seem to recognize the strtotime part of the code. It is outlined in red and says the function is unknown when I hover over it.

Is this perhaps a feature from a newer build?

Thnx again for responding to my request!

Please Log in to join the conversation.

More
2 years 10 months ago #106622 by tpartner
Ah, sorry, I assumed you are using 2.05.

It's a bit ugly but you can use nested IF() statements to handle the localization. Something like this (remove the line-breaks that I have added for clarity):
{if(date('F') == 'January', 'januari', 
  if(date('F') == 'February', 'februari', 
    if(date('F') == 'March', 'maart', 
      if(date('F') == 'April', 'april', 
        if(date('F') == 'May', 'mei', 
          if(date('F') == 'June', 'juni', 
            if(date('F') == 'July', 'juli', 
              if(date('F') == 'August', 'augustus', 
                if(date('F') == 'September', 'september', 
                  if(date('F') == 'October', 'oktober', 
                    if(date('F') == 'November', 'november', 
                      if(date('F') == 'December', 'december', 
                        ''))))))))))))}


And something similar for the previous months:
{if(date('F') == 'January', 'november', 
  if(date('F') == 'February', 'december', 
    if(date('F') == 'March', 'januari', 
      if(date('F') == 'April', 'februari', 
        if(date('F') == 'May', 'maart', 
          if(date('F') == 'June', 'april', 
            if(date('F') == 'July', 'mei', 
              if(date('F') == 'August', 'juni', 
                if(date('F') == 'September', 'juli', 
                  if(date('F') == 'October', 'augustus', 
                    if(date('F') == 'November', 'september', 
                      if(date('F') == 'December', 'oktober', 
                        ''))))))))))))}

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: Luneya

Please Log in to join the conversation.

More
2 years 10 months ago #106623 by Luneya
Thank you so much!

I hope we will upgrade to 2.05 soon haha ;)

In the meantime I will use this solution.

Have a great day and thanks again!

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form