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

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 :: systemverilog unique constraint unique values 
Sql :: trigger stock phpmyadmin output message 
Sql :: how to run sql script in postgresql in windows 
Sql :: SQL Create Named CHECK Constraint 
Sql :: select from another database 
Sql :: join creating duplicate columns sqllite 
Sql :: sql query wordpress export post 
Sql :: mysql page segment 
Sql :: how to connect .sql data set to powerbi 
Sql :: print intervals of 15 minutes in sql query 
Sql :: watch mysql command line 
Sql :: creating directory /var/lib/postgresql/data ... initdb: error: could not create directory "/var/lib/postgres/data": Permission denied 
Sql :: mysql insert into select with recursive 
Sql :: sqlalchemy query return only n results 
Sql :: PROSYS SQL 
Sql :: deny select insert update delete sql 
Sql :: inserting values with beekeeper get error null value in column createdAt violates not-null constraint 
Sql :: mysql db dump restore max file size issue 
Sql :: normal mysql large import 
Sql :: SQLite3::SQLException: table "categories" already exists: CREATE TABLE "categories" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL 
Sql :: could not find driver (SQL: PRAGMA foreign_keys = ON;) larave 
Sql :: suse status MySQL 
Sql :: How to fix a collation conflict in a SQL Server query 
Sql :: can we compare two timestamps in mysql 
Sql :: drop tables from local table database postgres 
Sql :: SQL Copy Table Schema Only 
Sql :: python mysql github 
Sql :: mysql primary vs unique 
Sql :: sql requete number pair 
Sql :: dbname+tablename 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =