How do I manipulate dates?

More
4 years 5 months ago #94433 by AbbyW
AbbyW created the topic: How do I manipulate dates?
I'm new to limesurvey and would like to get age on a certain date (01.01.2012) from the date of birth that is entered as the answer to a question. I figured I could just get the year from the date of birth with javascript (which I'm also new to). I tried to read it as a date and also as string, and am getting weird results. Any ideas what I'm doing wrong?

My code:

<script type="text/javascript" charset="utf-8">
document.write( "DOB = {INSERTANS:36485X1569X9272}<BR>");
var date1 = "{INSERTANS:36485X1569X9272}";
document.write("DOB1 : " + date1 + "<BR>");

var year1 = date1.substring(2);
document.write("Year : " + year1 + "<BR>");

var date2 = new Date("{INSERTANS:36485X1569X9272}");
document.write("DOB2 : " + date2 + "<BR>");
</script>



Output:
DOB = 12.01.2012
DOB1 : 12.01.2012
Year : pan id='LEMtailor_Q_9295_94'>
DOB2 : Invalid Date


Thanks so much!
Abby

Please Log in to join the conversation.

More
4 years 5 months ago #94434 by Ben_V
Ben_V replied the topic: How do I manipulate dates?

Benoît

EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now