Convert Short Date to Long Date


I have a survey in which I am using the “Date” question.  I am trying to figure out how to convert the date  to a long date (e.g. convert 09/01/2016 to September 1, 2016).  I want to store the long date as a hidden value.  I really do not understand JavaScript, so if someone in the community could help, I would greatly appreciate it.  Thanks.

IS answered
    IS 2.21K Rep.

    I myself am more familiar with php than JavaScript, so I prefer SG’s Custom Scripting which is based on php.

    If you have a Date question with question id 4 and a hidden value with id 5, on the next page you can create a one line custom script like this:

    sgapiSetValue(5, sgapiDate(“F j, Y”,sgapiGetValue(4)));

    I haven’t tested it, but I think that should work. For more info you can see the following pages:

    Mike Miller commented
      • Thanks so much for your assistance. So, this did not work. It gave me the following error: “Script Failed: Bad Script Syntax!” Perhaps it is in my setup. This is how I have it.

        Page 1: Date Question (ID=5)
        Page 2: Hidden Value – Date (ID=9)
        Page 3: Script – sgapiSetValue(9, sgapiDate(“F j, Y”,sgapiGetValue(5)));

        Any suggestions?

      • I just realized that sgapiGetValue probably does not return an actual date value. If it returns a string you may need to convert it to a date/time value. So something like:
        sgapiSetValue(9, sgapiDate(“F j, Y”,sgapiStrtotime(sgapiGetValue(5))));
        I will try some things and report back when I get a bit more time.

      • I think I see part of the problem. You do need to use the sgapiStrtotime function to convert the retrieved value to a time, but the primary reason for the error message you got is that the quotes are being converted to smart quotes by this message board system. When you copy and paste you end up with the wrong quote character. Try copying the script from my most recent comment and then type over the smart quotes with the quote character from your keyboard.

      • If there is a way to just format the output of the Date question without the extra steps (e.g. hidden values, etc.), I am certainly open to that as well.

      • I don’t think so. It seems that the dates are actually stored as text rather than as an actual date/time value. That means that tricks to display the date differently don’t work without first converting the text to a date/time. I think only some form of scripting will do that for you.

      • I got it to work!!! Thank you so much.



      Question stats

      • Active
      • Views9382 times
      • Answers1 answer
      • Followers1 follower