Watch, Follow, &
Connect with Us
Public Report
Report From:    [ Add a report in this area ]  
Report #:  30758   Status: Closed
EncodeDate boundaries inconsistent with Win32
Project:   Build #:  42451
Version:    10.0 Submitted By:   Joe White
Report Type:  Basic functionality failure Date Reported:  6/29/2006 7:30:13 AM
Severity:    Commonly encountered problem Last Updated: 3/20/2012 2:24:39 AM
Platform:    All platforms Internal Tracking #:   257036
Resolution: Feature Removed (Resolution Comments) Resolved in Build: : 6.0.1.6
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: None
Description
EncodeDate(1, 1, 1) is valid in Win32, but results in an exception in .NET. The Delphi/.NET EncodeDate, for no apparent reason, does not accept years prior to 100. (This despite the fact that TDateTime accepts them just fine.)

This means that there are valid values for TDateTime that cannot be returned from EncodeDate (for example, the *default* value of 1/1/0001 that you get if a variable is initialized to its default value). Round-tripping is a no-go.
Steps to Reproduce:
1. Write the following as a Win32 console app. Run it. No exception.
2. Run the same code as a .NET console app. Run it. Boom.

----

program Project3;

{$APPTYPE CONSOLE}

uses
  SysUtils;

begin
  EncodeDate(1, 1, 1);
end.
Workarounds
Use TDateTime.Create(1, 1, 1, 0, 0, 0, 0) instead of EncodeDate(1, 1, 1). (But if you want your code to compile in both Win32 and .NET, you're stuck with IFDEFs.)
Attachment
None
Comments

None

Server Response from: ETNACODE01