How to extract time from datetimepicker component in Delphi?

I have a datetimepicker component in the form of Delphi, and I would just like to get Time. When I look at a date in debug mode, I see 42544.621701, and I would just like to get a 0.621701date without a value.

+4
source share
2 answers

You can use the function Frac():

var
  Time: TTime;
...
  Time := Frac(DateTimePicker1.DateTime);

Or you can use a function System.DateUtils.TimeOf()that is just an inline wrapper around Frac()with a more descriptive name:

uses
  ..., DateUtils;

var
  Time: TTime;
...
  Time := TimeOf(DateTimePicker1.DateTime);
+9
source

, . . . TimeOf System.DateUtils.

 MyTime := TimeOf(MyDateTime);
+5

All Articles