- Posts: 10
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
validación de calendario y edad
- Fgluna12
- Topic Author
- Offline
- New Member
Less
More
3 years 5 months ago #207927
by Fgluna12
validación de calendario y edad was created 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
Espero su respuesta
Gracias!
H
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12920
- Thank you received: 3976
3 years 5 months ago - 3 years 5 months ago #207934
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic validación de calendario y edad
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.
manual.limesurvey.org/ExpressionScript_-...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:
Joffm
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.
manual.limesurvey.org/ExpressionScript_-...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:
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:
Last edit: 3 years 5 months ago by Joffm.
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12920
- Thank you received: 3976
3 years 5 months ago - 3 years 5 months ago #207943
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic validación de calendario y edad
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
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: 3 years 5 months ago by Joffm.
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12920
- Thank you received: 3976
3 years 5 months ago #207952
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic validación de calendario y edad
Disculpes:
Fecha minima:
date('Y-m-d',mktime(0,0,0,date('m'),sum(intval(date('d')),1),sum(intval(date('Y')),-Q1,-1)))
Joffm
Fecha minima:
date('Y-m-d',mktime(0,0,0,date('m'),sum(intval(date('d')),1),sum(intval(date('Y')),-Q1,-1)))
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.