La requete SQL du jour : l’age du capitaine
SET @DateDeNaissance='1965-12-28';
SELECT
case
when month(now()) - month(@DateDeNaissance) < 0 then year(now()) - year(@DateDeNaissance) -1
when month(now()) = month(@DateDeNaissance) then
IF(DAYOFMONTH(now()) - DAYOFMONTH(@DateDeNaissance) < 0,year(now())-year(@DateDeNaissance)-1,year(now())-year(@DateDeNaissance))
else
year(now())-year(@DateDeNaissance)
end AS ageDu Capitaine
tagged: mysql