0 0 Votes

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

Question by Guest | 23/10/2015 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

Delphian

Show Profile | Message
Avatar
0Best Answer
0 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.
24/10/2015 at 20:44

ReplyPositive Negative
Reply

Related Topics

PHP: Date 3 Months ago
Question | 1 Answer

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 articles on askingbox.com. How to do.