Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 7 of 7 total
Thread Databound Date Field Error
Thu, May 21 2015 7:42 AMPermanent Link

Eivind

I'm getting some strange errors when I have a TEdit bound to Date field in a Dataset. It does not matter what date I input, it will always return an error once I exit the control. I have tried with different and the default ShortDateFormat with no luck. After some digging, I found out by playing around with the UTC variable in the StrToDate function has something to do with it. Without any databound fiels I just try to call the StrToDate('21/07/1972, True) and it will return a invallid date error. (ShortDateFormat in this case is correct and is dd/MM/yyyy)

If I try StrToDate('21/07/1972, False), all is good. No error. Someone could elobrate what the UTC variable does? Probably not the right thing to to, but in the last line of the StrToDate function in the WebCore unit I put False instead on UTC in the Result:=EncodeDate(TempYear,TempMonth,TempDay,UTC). Now all is working good and the TEdit accepts my date value with no error. However, in the database the day is 20, not 21 as inputted.

Help please!

Eivind
Thu, May 21 2015 8:21 AMPermanent Link

Matthew Jones

Eivind wrote:

> Someone could elobrate what the UTC variable does?

My thinking, not changed when I read the manual, is that it is reading
in the UTC standard format, which would be YYYY-MM-DD.

http://www.w3.org/TR/NOTE-datetime-970915.html

Your examples seem to bear this out.
Thu, May 21 2015 8:48 AMPermanent Link

Uli Becker

Eivind,

<<
Now all is working good and the TEdit accepts my date value with no
error. However, in the database the day is 20, not 21 as inputted.
>>

Are you using EWBServer as webserver? If so, you can change the property
LocalizeDateTimeColumns in the "Connection Properties" of a DataSet.
That should do it.

Uli

Thu, May 21 2015 9:06 AMPermanent Link

Walter Matte

Tactical Business Corporation

This test worked for me.....

Use this format setting:

formatsettings.shortdateformat := 'd/M/yyyy';


procedure TForm1.Button4Click(Sender: TObject);
var
 stemp : string;
 dt : DateTime;
begin         
 sTemp := formatsettings.shortdateformat;
 //showmessage(stemp);

 formatsettings.shortdateformat := 'd/M/yyyy';

 dt := StrToDate('21/07/1972');

 Showmessage(datetostr(dt));

end;
Thu, May 21 2015 9:10 AMPermanent Link

Walter Matte

Tactical Business Corporation



Ahh - the UTC is not working properly.  this is adjusting for Zulu time.


This Fails.

StrToDate('21/07/1972',true);
Thu, May 21 2015 9:31 AMPermanent Link

Walter Matte

Tactical Business Corporation

I'll send bug report to Tim....


BUG - JavaScript generation bug.  If you don't compress JS and edit function encodedate.

function encodedate($0, $1, $2, $3)
{
  if ($3)
     var $1 = new Date(Date.UTC($0, $1 - 1, $2, 0, 0, 0, 0)).getTime();
  else
     var $4 = new Date($0, $1 - 1, $2, 0, 0, 0, 0).getTime();
  if (!isNaN($4))
     return $4;
  else
     throw "Invalid date value";
};


SHOULD BE:  (var $4 )

function encodedate($0, $1, $2, $3)
{
  if ($3)
     var $4 = new Date(Date.UTC($0, $1 - 1, $2, 0, 0, 0, 0)).getTime();
  else
     var $4 = new Date($0, $1 - 1, $2, 0, 0, 0, 0).getTime();
  if (!isNaN($4))
     return $4;
  else
     throw "Invalid date value";
};

Walter
Thu, May 21 2015 12:33 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Walter,

<< I'll send bug report to Tim.... >>

Got it, and it's fixed.  A build 9 will be out today that fixes this, and a
couple of other serious issues in build 8.

Tim Young
Elevate Software
www.elevatesoft.com
Image