11 Vote

Delphi/Lazarus: Convert Year, Month and Day to DateTime-Format

Question by Guest | 2015-12-02 at 17:42

I have an individual integer variable for year, month and day. I would like to create a date in the TDateTime format out of this values and convert them accordingly.

Is this possible using Delphi or Lazarus?

ReplyPositiveNegative
0Best Answer0 Votes

That is possibly without any problems in Delphi as a well as in Lazarus. We are using the function EncodeDate for this. Here is a small example.

uses DateUtils;

var
  ADate: TDateTime;
  AYear, AMonth, ADay: integer;
begin

  ADay   := 1;
  AMonth := 1; 
  AYear  := 2000; 

  ADate  := EncodeDate(AYear, AMonth, ADay);

  ShowMessage(DateToStr(ADateTime));
end;

We have some variables for the year, the day and the month and we are using EncodeDate in order to make a date out of the values and to store the data in a TDateTime variable. After that, we are showing the new dates using ShowMessage().
2015-12-02 at 19:47

ReplyPositive Negative
Reply

Related Topics

PHP: Current Date and Time

Tutorial | 0 Comments

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.