Search
 
SCRIPT & CODE EXAMPLE
 

SQL

mysql calculate age

SELECT DATEDIFF(CURRENT_DATE, STR_TO_DATE(t.birthday, '%d-%m-%Y'))/365 AS ageInYears
  FROM YOUR_TABLE t 
Comment

mysql get age from date

SELECT YEAR(CURRENT_DATE)-YEAR(t.birthday) AS ageInYears
  FROM YOUR_TABLE t 
Comment

mysql age by birthdate

mysql> SELECT DATE_FORMAT(FROM_DAYS(DATEDIFF(now(),YourDateofBirth)), '%Y')+0 AS Age from AgeCalculationFromDatetime;
Comment

compute age mysql

MySQL Compute a Persons Age
Comment

calculate age function in mysql

drop function if exists getIdade;

delimiter |

create function getIdade( data_nascimento datetime )
returns int
begin
    declare idade int;
    declare ano_atual int;
    declare mes_atual int;
    declare dia_atual int;
    declare ano int;
    declare mes int;
    declare dia int;

    set ano_atual = year(curdate());
    set mes_atual = month( curdate());
    set dia_atual = day( curdate());

    set ano = year( data_nascimento );
    set mes = month( data_nascimento );
    set dia = day( data_nascimento );

    set idade = ano_atual - ano;

    if( mes > mes_atual ) then
            set idade = idade - 1;
    end if;

    if( mes = mes_atual and dia > dia_atual ) then
            set idade = idade - 1;
    end if;

    return idade;
end|

delimiter ;
Comment

PREVIOUS NEXT
Code Example
Sql :: sql select except null 
Sql :: oracle cannot access v$session 
Sql :: Sql creating roles 
Sql :: sql drop table statement 
Sql :: remove all records from table mysql 
Sql :: select statement to print longest name 
Sql :: reset sql auto increment 
Sql :: sql insert query 
Sql :: mysql sum cast decimal without round 
Sql :: mysql shell ERROR: Not connected. 
Sql :: get latest record in sql 
Sql :: mysql select last row for each group 
Sql :: describe table query in postgresql 
Sql :: install postgresql on raspberry pi 
Sql :: oracle ORA-00054 origin 
Sql :: using distinct count in sqlite3 
Sql :: alter table auto_increment 
Sql :: mysql data types 
Sql :: org.h2.jdbc.jdbcsqlsyntaxerrorexception table not found 
Sql :: where date major today mysql 
Sql :: mysql reset root password 
Sql :: oracle alter table delete column 
Sql :: t-sql get duplicate rows 
Sql :: mysql order by desc null last 
Sql :: create unique index postgres 
Sql :: sql count having 
Sql :: convert rows to string sql server 
Sql :: mysql order 
Sql :: mysql inner join 3 tables 
Sql :: execute mysql file 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =