0

This is my table.

create table ator(
numero_identidade varchar2(10) NOT NULL,
numero_ss varchar2(20) NOT NULL,
dt_nascimento date NOT NULL,
nacionalidade varchar2(20) NOT NULL,
nome_artistico varchar2(40),
sexo char(1) NOT NULL,
idade number(2,0) NOT NULL,
primary key (numero_identidade),
CONSTRAINT sexo_a check (sexo = 'F' or sexo = 'M'));


SELECT DATEDIFF(idade,GETDATE())/8766 AS AgeYearsIntTrunc

i have've seen this command on the internet but i don't understand how to use it.

how can i do that??

Filipe Mota
  • 137
  • 8

2 Answers2

2

If you are using Oracle DBMS try with:

SELECT TRUNC(MONTHS_BETWEEN(SYSDATE, dt_nascimento)/12) AS idade FROM your_table
davidm
  • 1,570
  • 11
  • 24
0

This is what you saw:

> DATEDIFF(hour,idade,GETDATE())/8766 AS AgeYearsIntTrunc

It takes the difference in hours and divide it by the number of hours in a year: 365.25*24 = 8766. That means you end up having the age in years. Hope this help. . Just try

select DATEDIFF(hour,idade,GETDATE())/8766 AS AgeYearsIntTrunc
from ator
zip
  • 3,938
  • 2
  • 11
  • 19