Welcome to the LimeSurvey Community Forum

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

validación de calendario y edad

More
4 years 9 months ago #207927 by Fgluna12
Hola, soy nuevo, tengo dos preguntas, una es ¿Cuál es su edad? y la otra es una pregunta de tipo fecha que pregunta ¿Cuándo nació? me gustaría validar que salga un error cuando no coincida la edad con el año de fecha.
Espero su respuesta
Gracias!
H
The topic has been locked.
More
4 years 9 months ago - 4 years 9 months ago #207934 by Joffm
Hola,
Si tengo X años hoy significa:
Mi cumpleaños de X años es entre hoy y mañana hace un año.
Ejemplo:
Tengo 70, significa mi cumpleaños es entre el once de noviembre 2019 y el diez de noviembre 2020.

Vea qué funciones hay.
www.limesurvey.org/manual/ExpressionScri...mplemented_functions
Entonces tenemos:
mktime
www.php.net/manual/es/function.mktime.php
y
date
www.php.net/manual/es/function.date.php

Así es como calculamos los datos
1. este dia antes de X años: date('Y-m-d',mktime(0,0,0,date("n"),date("j"),date("Y")-Q1))
2. este dia antes de X+1 años: date('Y-m-d',mktime(0,0,0,date("n"),date("j"),date("Y")-Q1-1)))
Q1 el codigo de la pregunta por la edad.

Y así validamos:
is_empty(self) OR (self le date('Y-m-d',mktime(0,0,0,date("n"),date("j"),date("Y")-Q1)) and self gt date('Y-m-d',mktime(0,0,0,date("n"),date("j"),date("Y")-Q1-1)))

is_empty(self) para para evitar que aparezca un mensaje de error si no se ingresa nada.

Y un mensaje de validación como
Fecha mas grande que {date('d.m.Y',mktime(0,0,0,date("n"),date("j"),date("Y")-Q1-1))} y más pequeño o igual {date('d.m.Y',mktime(0,0,0,date("n"),date("j"),date("Y")-Q1))}







Y el ejemplo:

File Attachment:

File Name: limesurvey...6362.lss
File Size:16.37 KB


Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 4 years 9 months ago by Joffm.
The topic has been locked.
More
4 years 9 months ago - 4 years 9 months ago #207943 by Joffm
Quizas mejor (sin validación):


Fecha minima:
date('Y-m-d',mktime(0,0,0,date('m'),sum(intval(date('d')),-1),sum(intval(date('Y')),-Q1,-1)))

Fecha maxima:
date('Y-m-d',mktime(0,0,0,date('m'),intval(date('d')),sum(intval(date('Y')),-Q1)))

Q1: codigo de la pregunta: "Cual es su edad?"



Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 4 years 9 months ago by Joffm.
The topic has been locked.
More
4 years 9 months ago #207952 by Joffm
Disculpes:
Fecha minima:
date('Y-m-d',mktime(0,0,0,date('m'),sum(intval(date('d')),1),sum(intval(date('Y')),-Q1,-1)))

File Attachment:

File Name: limesurvey...62_2.lss
File Size:16.16 KB

Joffm

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

Lime-years ahead

Online-surveys for every purse and purpose