MySQL Forums
Forum List  »  Spanish

Re: Problema Consulta Fecha Nacimiento
Posted by: Jesús Uzcanga
Date: July 02, 2014 11:05AM

Jaier ya tenías la tarea casi lista, solo había que analizar un poco el código y tomar como base el cálculo del año.

SELECT NOMBRE,DATE(fecha_nac) FechaNacimiento,

YEAR(CURDATE())-YEAR(`fecha_nac`)+
IF(DATE_FORMAT(CURDATE(),'%m-%d') > DATE_FORMAT(`fecha_nac`,'%m-%d'), 0, -1) AS `AÑOS`

,IF(DATE_FORMAT(`fecha_nac`,'%m') - DATE_FORMAT(CURDATE(),'%m')<=0,MONTH(CURDATE())-MONTH(`fecha_nac`),12+(MONTH(CURDATE())-MONTH(`fecha_nac`))) as `MESES`

,IF(DATE_FORMAT(`fecha_nac`,'%d') - DATE_FORMAT(CURDATE(),'%d')<=0,DAY(CURDATE())-DAY(`fecha_nac`),30+(DAY(CURDATE())-DAY(`fecha_nac`))) as `DIAS`

FROM `personas`

WHERE nombre='pedro';

___________________________
Ing. Jesús Alfredo Uzcanga
Twitter: @JesusUzcanga

We learn the 20% of what we HEAR,
the 50% of what we SEE,
the 80% of what we DO and
the 95% of what we TEACH.

____________________________________________________________
https://www.linkedin.com/in/jauzcanga/

Options: ReplyQuote


Subject
Views
Written By
Posted
1654
June 25, 2014 01:21PM
Re: Problema Consulta Fecha Nacimiento
969
July 02, 2014 11:05AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.