Welcome to the LimeSurvey Community Forum

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

date calculation with relevance equation problem

  • jboogie21
  • jboogie21's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
8 years 11 months ago #118511 by jboogie21
I'm using this code to determine whether or not a group of questions should be displayed:
Code:
(strtotime('now')-strtotime(TOKEN:ATTRIBUTE_3))/60/60/24/365 <=5

The desired function is to display a group of questions if the calculated age based on a birthdate in the token table in the format mm/dd/yyyy is <= 5.

What I discovered is that for the equation to calculate correctly, the birthdate has to be at least 2 days from the time the survey was started for the equation to work. For example, I start the survey today (i.e. 3/20/2015), the token field birthdate has to be at least 3/22/2010 before the calculation meets the condition and shows the group of questions for <=5. This does not seem right, as the child's birthday is 3/21/2010 and I start the survey on 3/20/2015 I should still get the questions for the <=5 people as I don't turn 5 until the following day (3/21/2015) from when I started the survey.

I imagine this might be a number formatting/round issues. Has anyone experienced this or can provide any guidance?
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 11 months ago #118518 by holch
I would guess that there have been 2 leap years within the last 5 years, which would explain the 2 days difference, wouldn't it?

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 11 months ago - 8 years 11 months ago #118526 by tpartner
You can use this to get an accurate timestamp of 5 years before today:

Code:
{mktime(0, 0, 0, date("m"), date("d"), date("Y")-5)}

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 8 years 11 months ago by tpartner.
The topic has been locked.
  • jboogie21
  • jboogie21's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
8 years 11 months ago #118567 by jboogie21
Replied by jboogie21 on topic date calculation with relevance equation problem
Ahh leap years. That makes sense. Also, thanks Tony for the tip! I'll try that.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose