How do I apply a date format to a question ID?


example 1: [question(“value”), id=”29″,format=”Y-m-d”]

example 2: [system(“date”),format=”Y-m-d”]


I can’t figure out the syntax to make example 1 work. Example 2 works without a problem!

Alex Walker answered

    Custom scripts are scary at first, but once you understand them you really start to see possibilities.

    Give it a try – insert an ACTION > CUSTOM SCRIPT on the survey page after the date question and copy/paste this script:

    %%xdate = sgapiStrtotime(sgapiGetValue(29));
    %%xdate = sgapiDate(“Y-m-d”,%%xdate);
    %%output .= %%xdate;

    The OUTPUT command should cause the date that was entered into qid29  to appear on the page in the YYYY-mm-dd format.  If it works, your next step should be to replace the OUTPUT command with a line that places the xdate as a response to a question:

    sgapiSetValue(??, %%xdate);

    The question marks (??) should be replaced by the question ID.  If you don’t want your respondent yo see the question then you can edit the question and use LOGIC RULE > HIDE THIS QUESTION BY DEFAULT.  This question would be the one that you pass to your application.

    Jim W (Moderator) answered

      I’m just passing it to another application which expects a text string which looks like YYYY-MM-DD. 

      If I were facing a similar problem in Excel, I’d start doing things like (left, 4 characters), (right, 2 characters) etc. and then piece it back together.

      Is that more or less hassle than custom scripting – as I’m not at all familiar with scripting?

      Alex Walker answered

        You will have to write a custom script.

        The problem is that the data returned by the question’s merge code is actually text data and not date.  So in order to format it you will first have to convert the response from text to date.  This is a  three step process.  You would first use the sgapiGetValue function to get the response and the use the sgapiStrtotime function to convert the response from text to date.  You could then use the sgapiDate function to format the date.  Review the following example:

        %%xdate = sgapiStrtotime(sgapiGetValue(29));
        %%xdate = sgapiDate(“l”,%%xdate);

        I am not sure how you intend to use the date, so I am not sure what you would do with the ‘xdate’ variable.  One option would be to use the sgapiSetValue function to place the date in a hidden question.

        Jim Wetherill answered


          Question stats

          • Active
          • Views23289 times
          • Answers8 answers
          • Followers1 follower