#1 2025-11-20 05:18:17

ertank
Member
Registered: 2016-03-16
Posts: 186

Converting all datetime values in a record to localtime

Hello,

I am using Delphi 12.3 and looking for an advise on a way to convert all TDateTime variables values from GMT+0 to a different GMT in a packed record which has lots of other variables and different data types.
What I am looking for is something like an utility function that I do not need to use record variable names in code.

Is that possible? Or I still need to change all of them one by one in classical way.

Thanks & Regards,
Ertan

Offline

#2 2025-11-20 07:28:04

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,328
Website

Re: Converting all datetime values in a record to localtime

record or class?

You can use TRttiCustom.Props do check for TDateTime fields.

Offline

#3 2025-11-20 10:06:54

ertank
Member
Registered: 2016-03-16
Posts: 186

Re: Converting all datetime values in a record to localtime

Thank you for the help.
I need it for record

Offline

#4 2025-11-21 08:46:03

rvk
Member
Registered: 2022-04-14
Posts: 144

Re: Converting all datetime values in a record to localtime

For completeness, here is a example changing all TDateTime in a record using TRttiContext in Delphi:

https://gist.github.com/rvk01/6a1cba7da … f4dc5ed407

Offline

#5 Today 03:15:36

zen010101
Member
Registered: 2024-06-15
Posts: 139

Re: Converting all datetime values in a record to localtime

another demo, tested with FPC:

https://gist.github.com/zen010101/4af9a … ebe62f19a9

Usage:

  var
    Rec: TMyRecord;
  begin
    // ... populate Rec ...

    // Convert from UTC to GMT+8
    ConvertRecordDateTimesToTimezone(Rec, TypeInfo(TMyRecord), 8);

    // Convert from UTC to EST (GMT-5)
    ConvertRecordDateTimesToTimezone(Rec, TypeInfo(TMyRecord), -5);
  end;

Offline

Board footer

Powered by FluxBB