[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 718
  • Last Modified:

SystemTimeToDateTime

It's 4:20 in the morning, and this is really annoying me.  Calling this function produces a debugger exception notification with the following error message:

"Invalid argument to date encode."

The problem line is the call to SystemTimeToDateTime, though I don't see why.  TZSystem.StandardDate is a _SYSTEMTIME, and SystemTimeToDateTime wants a _SYSTEMTIME, so what's the problem?

procedure ProcedureName;
var
  TZSystem: TTimeZoneInformation;
  DateTime: TDateTime;
begin
  GetTimeZoneInformation(TZSystem);

  DateTime := SystemTimeToDateTime(TZSystem.StandardDate);
end;

Brian
0
Traal
Asked:
Traal
1 Solution
 
TOndrejCommented:
Read the documentation of GetTimeZoneIformation.
StandardDate is not really a valid _SYSTEMTIME. It's purpose is to specify when the transition from daylight saving time to standard time occurs, using a special notation.
First of all, it may not even be specified, in which case wMonth = 0.
If it is specified, then wYear = 0, wDayOfWeek contains the day of week, wDay contains a value in the range 1 - 5 (1 meaning the first wDayOfWeek, 5 meaning the last).
For example:
wYear = 0, wMonth = 4, wDayOfWeek = 0, wDay = 1
would mean "first Sunday in April".

The other members of the structure are IMHO undefined and not used.

HTH
TOndrej
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now