Welcome, Guest
Username: Password: Remember me

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

add current month to var to re-use in multiple questions 7 months 17 hours ago #106607

  • Luneya
  • Luneya's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 8
  • Karma: 0
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
The administrator has disabled public write access.

add current month to var to re-use in multiple questions 7 months 14 hours ago #106612

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4281
  • Thank you received: 807
  • Karma: 370
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Last Edit: 7 months 14 hours ago by tpartner.
The administrator has disabled public write access.
The following user(s) said Thank You: Luneya

add current month to var to re-use in multiple questions 7 months 13 hours ago #106615

  • Luneya
  • Luneya's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 8
  • Karma: 0
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!
The administrator has disabled public write access.

add current month to var to re-use in multiple questions 7 months 12 hours ago #106622

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4281
  • Thank you received: 807
  • Karma: 370
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
The following user(s) said Thank You: Luneya

add current month to var to re-use in multiple questions 7 months 12 hours ago #106623

  • Luneya
  • Luneya's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 8
  • Karma: 0
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!
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.328 seconds
Donation Image