Como extrair mes e ano?

Delphi

19/01/2004

Como eu faço para extrair o mes e o ano de um TDateEdit para variáveis que eu declaro?

EX:

var
mes : Integer;
ano : Integer;


Valor do TDateEdit = 25/02/2004

mes := mes da data(02)
ano := ano da data(2004)


Havilux

Havilux

Curtidas 0

Respostas

Maicongabriel

Maicongabriel

19/01/2004

Assim
var
  Mes, Ano : Integer;
begin
  Mes := StrToInt(FormatDateTime(´MM´, DateTimePicker1.Date));
  Ano := StrToInt(FormatDateTime(´YYYY´, DateTimePicker1.Date));
end


ou com [b:9146cafe50]DateUtils[/b:9146cafe50] na uses se o seu delphi for superior ou igual ao 6.
var
  Mes, Ano : Integer;
begin
  Ano := YearOf(DateTimePicker1.Date);
  Mes := MonthOf(DateTimePicker1.Date);
end;



GOSTEI 0
POSTAR