[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/session.php on line 594: sizeof(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/session.php on line 650: sizeof(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/session.php on line 1110: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3903)
[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/session.php on line 1110: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3903)
[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/session.php on line 1110: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3903)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 113: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 113: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 113: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 5277: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3903)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 5277: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3903)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 5277: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3903)
Fórum Xmaker • Retornar idade!!! (RESOLVIDO!!!)
Página 1 de 1

Retornar idade!!! (RESOLVIDO!!!)

Enviado: Outubro 5th, 2011, 1:04 pm
por Dimmy Angelo
Como faço pra retornar a idade em anos apartir da idade de nascimento.

Obrigado, aguardo!!!

Re: Retornar idade!!!

Enviado: Outubro 5th, 2011, 6:02 pm
por carlinhos.info
Colega escreva está function no formulario Rotinas.pas


function CalculaIdade(DataIni, DataFim : TDateTime) : string;
var Idade : String;
iDia, iMes, iAno, fDia, fMes, fAno : Word;
nDia, nMes, nAno : Double;
begin
DecodeDate(DataIni,iAno,iMes,iDia);
DecodeDate(DataFim,fAno,fMes,fDia);
nAno := fAno - iAno;
if nAno > 0 then
if fMes < iMes then nAno := nAno - 1
else if(fMes = iMes)and(fDia < iDia)then nAno := nAno - 1;

if fMes < iMes then
begin
nMes := 12 - (iMes-fMes);
if fDia < iDia then nMes := nMes - 1;
end
else if fMes = iMes then
begin
nMes := 0;
if fDia < iDia then nMes := 11;
end
else if fMes > iMes then
begin
nMes := fMes - iMes;
if fDia < iDia then nMes := nMes - 1;
end;
nDia := 0;

if fDia > iDia then nDia := fDia - iDia;
if fDia < iDia then nDia := (DataFim-IncMonth(DataFim,-1))-(iDia-fDia);
Result := '';
if nAno = 1 then Result := AjustarStr(FloatToStr(nAno),3)+ ' Ano '
else if nAno > 1 then Result := AjustarStr(FloatToStr(nAno),3)+ ' Anos ';

if nMes = 1 then Result := Result + FloatToStr(nMes)+ ' Mês '
else if nMes > 1 then Result := Result + FloatToStr(nMes)+ ' Meses ';

if nDia = 1 then Result := Result + FloatToStr(nDia)+ ' Dia '
else if nDia > 1 then Result := Result + FloatToStr(nDia)+ ' Dias ';
end;

Exemplo: Idade := CalculaIdade(DataNacto, DatadoDia);

Re: Retornar idade!!!

Enviado: Outubro 6th, 2011, 8:51 am
por Dimmy Angelo

Re: Retornar idade!!!

Enviado: Outubro 6th, 2011, 1:47 pm
por carlinhos.info
Sim faltou mesmo a rotina para alinhar os resultados numericos.
Caso não queira este alinhamento basta remover a function AjustaStr da Rotina.

function AjustarStr ( str: String; tam: Integer ): String;
begin
while Length ( str ) < tam do
str := ' ' + str;
if Length ( str ) > tam then
str := Copy ( str, 1, tam );
Result := str;
end;

Re: Retornar idade!!!

Enviado: Outubro 7th, 2011, 9:16 am
por Dimmy Angelo

Re: Retornar idade!!!

Enviado: Outubro 7th, 2011, 9:22 am
por Dimmy Angelo

Re: Retornar idade!!!

Enviado: Outubro 7th, 2011, 10:00 am
por Dimmy Angelo
Outra dúvida, como faço para não aparecer 111 antes que seja informada a data de nascimento, quero que aparece em branco ou 0.

Obrigado !!!

Re: Retornar idade!!!

Enviado: Outubro 7th, 2011, 5:21 pm
por carlinhos.info
Voce pode testar o campo e caso ele esteja vazio você coloque Result := '';

if TabGlobal.DFLOW.DATA.Conteudo = Date-Date then Result := '' {ou 'Data não Informada'}
else Result := CalculaIdade(TabGlobal.DFLOW.DATA.Conteudo,DataAtual);