ULTIMO DIA DO MES
COMO FAÇO PARA PEGAR O ULTIMO DIA DE CASA MES....????
BJO
MILA
BJO
MILA
Anonymous
Curtidas 0
Respostas
Anonymous
25/02/2003
:oops: Não é exatamente o q. vc pediu mas acho q. da prá aprender e aprimorar um rotina...
{ Esta função retorna true se a data passada como parâmetro é fim de mês. Retorna false caso contrário. }
function tbFimDoMes(const Data: TDateTime): boolean;
var
Ano, Mes, Dia: Word;
begin
DecodeDate(Data +1, Ano, Mes, Dia);
Result := Dia = 1;
end;
{ Esta função retorna true se a data passada como parâmetro é fim de mês. Retorna false caso contrário. }
function tbFimDoMes(const Data: TDateTime): boolean;
var
Ano, Mes, Dia: Word;
begin
DecodeDate(Data +1, Ano, Mes, Dia);
Result := Dia = 1;
end;
GOSTEI 0
Anonymous
25/02/2003
faz uma function que recebe mes e ano e retorna o ultimo dia...
function ultimo_dia(mes: integer; ano:integer): integer;
begin
if (mes = 4) or (mes = 6) or (mes = 9) or (mes = 11) then
Result := 30
else if (mes = 2) and ((ano / 4) = int(ano / 4)) then
Result := 29
else if mes = 2 then
Result := 28
else
Result := 31;
end;
function ultimo_dia(mes: integer; ano:integer): integer;
begin
if (mes = 4) or (mes = 6) or (mes = 9) or (mes = 11) then
Result := 30
else if (mes = 2) and ((ano / 4) = int(ano / 4)) then
Result := 29
else if mes = 2 then
Result := 28
else
Result := 31;
end;
GOSTEI 0
Anonymous
25/02/2003
Baseando-se na data que vc está trabalhando faça o seginte:
var
dia, mes, ano : word;
tmp : tdatetime;
begin
dia := 1;
mes := //recebe o mês da sua data + 1;
ano := //recebe o ano que vc está manipulando.
encodedate(tmp, ano, mes, dia);
tmp := tmp-1; //aqui o delphi pegará a data (dia 1 do mes seguinte) e subtrairá 1, resultado no último dia do mes anterior.
end;
O usual é encapsular esta rotina numa função passando para ela a data em que se está manipulando.
var
dia, mes, ano : word;
tmp : tdatetime;
begin
dia := 1;
mes := //recebe o mês da sua data + 1;
ano := //recebe o ano que vc está manipulando.
encodedate(tmp, ano, mes, dia);
tmp := tmp-1; //aqui o delphi pegará a data (dia 1 do mes seguinte) e subtrairá 1, resultado no último dia do mes anterior.
end;
O usual é encapsular esta rotina numa função passando para ela a data em que se está manipulando.
GOSTEI 0
Durvalcastro
25/02/2003
8) Utilize esta função:
function DiasNoMes(AYear, AMonth: Integer): Integer;
const DaysInMonth: array[1..12] of Integer = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
begin
//Retorna quantos dias tem um mês específico
Result := DaysInMonth[AMonth];
if (AMonth = 2) and IsLeapYear(AYear) then Inc(Result);
end;
function DiasNoMes(AYear, AMonth: Integer): Integer;
const DaysInMonth: array[1..12] of Integer = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
begin
//Retorna quantos dias tem um mês específico
Result := DaysInMonth[AMonth];
if (AMonth = 2) and IsLeapYear(AYear) then Inc(Result);
end;
GOSTEI 0
Anonymous
25/02/2003
Desenvolvi essa função[zinha], espero q lhe ajude.
function UltimoDiaMes(iMes: integer): integer;
var
aUltimoDia: array[1..12] of integer;
iCont, iAno: integer;
begin
if (iMes>=1) and (iMes<=12) then
begin
iAno := StrToInt(FormatDateTime(´yyyy´, Date));
for iCont := 1 to 12 do
begin
if iCont in [1,3,5,7,8,10,12] then
aUltimoDia[iCont] := 31
else
if iCont in [4,6,9,11] then
aUltimoDia[iCont] := 30
else
begin
if (iAno mod 2)=0 then {Teste de ano bissexto}
aUltimoDia[iCont] := 29
else
aUltimoDia[iCont] := 28
end;
end;
end;
Result := aUltimoDia[iMes];
end;
function UltimoDiaMes(iMes: integer): integer;
var
aUltimoDia: array[1..12] of integer;
iCont, iAno: integer;
begin
if (iMes>=1) and (iMes<=12) then
begin
iAno := StrToInt(FormatDateTime(´yyyy´, Date));
for iCont := 1 to 12 do
begin
if iCont in [1,3,5,7,8,10,12] then
aUltimoDia[iCont] := 31
else
if iCont in [4,6,9,11] then
aUltimoDia[iCont] := 30
else
begin
if (iAno mod 2)=0 then {Teste de ano bissexto}
aUltimoDia[iCont] := 29
else
aUltimoDia[iCont] := 28
end;
end;
end;
Result := aUltimoDia[iMes];
end;
GOSTEI 0
Anonymous
25/02/2003
8) Utilize esta função:
function DiasNoMes(AYear, AMonth: Integer): Integer;
const DaysInMonth: array[1..12] of Integer = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
begin
//Retorna quantos dias tem um mês específico
Result := DaysInMonth[AMonth];
if (AMonth = 2) and IsLeapYear(AYear) then Inc(Result);
end;
Complementando
function IsLeapYear(AYear: Integer): Boolean; begin Result := (AYear mod 4 = 0) and ((AYear mod 100 <> 0) or (AYear mod 400 = 0)); end;
GOSTEI 0