[fpc-pascal] Timezone information in a dataset datetime field? - updated

Reinier Olislagers reinierolislagers at gmail.com
Sat Jul 23 18:41:12 CEST 2011

Hi all,

I'm busy with writing an XML export unit targeting Microsoft Access/.Net
framework (ADO.NET data access framework in particular).

Runing an ADO.NET demo program I found out that the ADO.NET variant
requires timezone info in its date/time fields.
In a sample export I did, it is set to my timezone (UTC+2 at this moment).

1. Is there any way of knowing what kind of timezone a datetime value
should be in a FPC dataset? (I suppose not...)

2. If not, I think I'm going to just use the current timezone. Is there
any cross-platform way of doing this? In the docs, I just found
GetLocalTimezone/TZSeconds in e.g. the linux unit... I could of course
use the Windows API to get something similar on Windows, but what about
OSX, or BSD or Solaris...

I found some code thread How to get UTC time from 2007:
would that still be the best solution?

2a: Unix:

{$mode Delphi}
uses unix,sysutils,baseunix;

 function utc_now : TDateTime;
   timeval: TTimeVal;
   timezone: PTimeZone;
   a: Double;
   TimeZone := nil;
   fpGetTimeOfDay (@TimeVal, TimeZone);
   // Convert to milliseconds
   a := (TimeVal.tv_sec * 1000.0) + (TimeVal.tv_usec / 1000.0);
   Result := (a / MSecsPerDay) + UnixDateDelta;

2b: Windows:
{$ifdef MSWINDOWS}
{ This uses SysUtils and Windows. }
function emt_now: TDateTime;
  st: TSystemTime;
  GetSystemTime (st);
  Result := SystemTimeToDateTime (st);


More information about the fpc-pascal mailing list