00 Votes

Delphi/Lazarus: Get TDateTime from Day, Month, Year, Hours, Minutes and Seconds

Question by Guest | 2015-10-23 at 18:35

I have some integer variables for the day, the month, the year, the hour, the minute and the second and I would like to transform this information into the DateTime format. So, I would like to create date and time out of the individual parts.

Is there any ready function for that in Delphi or Lazarus or do I have to write my own one?

ReplyPositiveNegative
0Best Answer0 Votes

You do not have to write any code function for this. Delphi as a well as Lazarus are knowing the function EncodeDateTime with which exactly your purpose is possible. Here you can see a small example for usage:

uses DateUtils;

var
  ADateTime: TDateTime;
begin
  ADateTime := EncodeDateTime(2020, 1, 1, 20, 00, 00);
  ShowMessage(DateToStr(ADateTime));
  ShowMessage(TimeToStr(ADateTime));
end;

In this example, we are setting the variable ADateTime to the date 1.1.2020 and the time 20:00:00. After that, we are showing date and time as message.

Important: we have to add the unit DateUtils to our uses-section to make it work.
2015-10-24 at 20:44

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.