For Newbie

Tuesday, 15 November 2011

The trick to take the separate (split) "date", "month" and "years" of the input type TDate.



Function declaration:
type
   rDate = record
     cdate: Byte;
     cmonth: Byte;
     cyears: Integer;
   end;

function splitdate (Date: TDate): rDate;
var
   date, month, year: Word;
begin
   DecodeDate (date, year, month, date);
   with Result do
   begin
     cdate = date;
     cmonth: = month;
     cyears: = yr;
   end;
end;

Example of implementation:
procedure TForm1.Button1Click (Sender: TObject);
var
   D: rDate;
begin
   D:  splitdate(DateTimePicker1.Date);
   with Memo1.Lines do
   begin
     Clear;
     Add ('Date =' + IntToStr (D.cdate));
     Add ('Month =' + IntToStr (D.cmonth));
     Add ('Year =' + IntToStr (D.cyears));
   end;
end;

Share on Facebook
Share on Twitter
Share on Google+

Related : The trick to take the separate (split) "date", "month" and "years" of the input type TDate.