Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Find the difference between 2 dates using only months in Limesurvey

More
3 years 7 months ago - 3 years 7 months ago #204578 by Lilit
Hello! I have two date variables. The first one is the day of the interview and the other is a person's date of birth.
I am trying to find the number of days between the day of the interview and the birth date so that if I have dates of birth of multiple people, I can choose the one whose birthday is the closest to today (it is a way to do a random selection). For instance, if the person was born on 25/08/1992 and today is 27/08/1992, the output is supposed to be 2 days (meaning that we used only days and months). How can I do that in Limesurvey?

Thanks in advance!
Last edit: 3 years 7 months ago by Lilit.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 7 months ago #204585 by tpartner
I'm not sure I understand "using only months " but you can use the strtotime() function in an Equation type question to find the difference between dates.

Something like this will give the difference in days between the current date and a value entered in a Date type question:

Code:
{floor((strtotime('now')-strtotime(birthday))/(60*60*24))}

Sample survey attached:

File Attachment:

File Name: limesurvey...5(2).lss
File Size:16 KB

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: DenisChenu
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 7 months ago #204588 by Joffm
Do you want to replicate this selection procedure "Ask the person whose birthday anniversary is next"?
This would mean that the year is not relevant.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose