Convert a TValue into TDateTime

1.3k Views Asked by At

How can I convert a TValue in TDateTime?

I see there are methods like AsInteger, AsDouble, etc. but nothing for TDateTime.

var
  c : TRttiContext;
  t : TRttiType;
  f : TRttiField;
  fieldValue : TValue;
  fieldDateValue : TDateTime;
begin
  c := TRttiContext.Create;
    t := c.GetType(Self.ClassType);
    for f in t.GetFields do begin
      fieldValue := field.GetValue(Self);
      //convert the TValue in TDateTime
    end;
end;
1

There are 1 best solutions below

0
On BEST ANSWER

The concrete AsXXX methods (like AsInteger) are just shortcuts to some intrinsic types (and some are also implemented with optimizations for the specific type). But to get any type from a TValue you can use the AsType<T> method.