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 :: error code 1175 mysql fix 
Sql :: mysql id reset 
Sql :: mysql create database charset utf8mb4 
Sql :: how to see logical reads in sql server 
Sql :: jooq convert using gbk 
Sql :: postgres remove foreign key constraint 
Sql :: mysql get count of rows 
Sql :: mysql return text after a final full stop 
Sql :: sql set auto increment back to 0 
Sql :: mysql show table column full description 
Sql :: pop sql insert value into 
Sql :: Disabling foreign key checks while performing Sqlalchemy Upgrade 
Sql :: function difference_in_hours(timestamp with time zone) does not exist 
Sql :: grant all privileges mysql 8.0.21 
Sql :: postgresql division count return 0 
Sql :: Query the list of CITY names from STATION that do not start with vowels and do not end with vowels. Your result cannot contain duplicates. 
Sql :: oracle db create new schema 
Sql :: $query = mysqli_query($con, $sql); while ($row = mysqli_fetch_array($query)) 
Sql :: mssql cursor 
Sql :: create another table from existing table sql oracle 
Sql :: postgresql add alter permissions to role 
Sql :: select from array in psql 
Sql :: if then else sqlite 
Sql :: get last record in sql 
Sql :: select first rows postgresql 
Sql :: sysdate in sql 
Sql :: psql: FATAL: Ident authentication failed for user "postgres" 
Sql :: installing postgresql ubuntu 
Sql :: show processlist mysql full query 
Sql :: data directory postgresql 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =