Search code examples
delphidatetimepicker

How do I extract just the time from a datetimepicker component in Delphi?


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


Solution

  • You can use the Frac() function:

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

    Or, you can use the System.DateUtils.TimeOf() function, which is merely an inlined wrapper around Frac() with a more descriptive name:

    uses
      ..., DateUtils;
    
    var
      Time: TTime;
    ...
      Time := TimeOf(DateTimePicker1.DateTime);