Recent

Author Topic: [SOLVED] TDBDateEdit component defaults to 12/30/1899  (Read 808 times)

1HuntnMan

  • Sr. Member
  • ****
  • Posts: 252
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
[SOLVED] TDBDateEdit component defaults to 12/30/1899
« on: September 10, 2024, 11:41:52 pm »
Anyone know how to get rid of the default on TDBDateEdit to 12/30/1899?  Even if I default to the current date, it still appears as 1899???
« Last Edit: September 12, 2024, 09:16:42 pm by 1HuntnMan »

wp

  • Hero Member
  • *****
  • Posts: 12364
Re: TDBDateEdit component defaults to 12/30/1899
« Reply #1 on: September 11, 2024, 12:04:56 am »
This happens when you initialize empty date fields with zero rather than with NULL (because date zero is 12/30/1899).

I found the attached project which demonstrates this.

1HuntnMan

  • Sr. Member
  • ****
  • Posts: 252
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
Re: TDBDateEdit component defaults to 12/30/1899
« Reply #2 on: September 11, 2024, 07:43:22 pm »
So, this is incorrect the way I've been defining tables:

Code: Pascal  [Select][+][-]
  1.    with SalesOrders.FieldDefs do begin
  2.      Add('ORDERNO', ftAutoInc, 4, True);
  3.      Add('ORDERDATE', ftDate, 8, True); //->Should be False here correct?
  4.      Add('JOBNAME', ftString, 35, True);
  5.      Add('CLIENT', ftString, 45, True);
  6.      Add('TYPEFIRM', ftString, 20, True);
  7.      Add('REQBYLNAME', ftString, 15, True);
  8.      Add('REQBYFNAME', ftString, 15, True);
  9.      Add('REQBYMI', ftString, 1, True);
  10.      Add('TITLE', ftString, 25, True);
  11.      Add('CLNTPHONE', ftString, 23, True);
  12.      Add('REQBYCELL', ftString, 23, True);
  13.      Add('REQBYEMAIL', ftString, 45, True);
  14.      Add('PHOTOREP', ftString, 35, True);
  15.      Add('PROJECTLEADER', ftBoolean, 1, True);
  16.      Add('SOAUTHORIZED', ftBoolean, 1, True);
  17.      Add('JOBCOMPLETED', ftDate, 1, True);
  18.      Add('JOBDUEDATE', ftDate, 8, True);//-> ftDate, Null, True ????
  19.      Add('ESTPRICE', ftFloat, 7, True);
  20.      Add('FIXEDPRICE', ftFloat, 7, True);
  21.      Add('MAXPRICE', ftFloat, 7, True);
  22.      Add('QUANTITY', ftSmallint, 4, True);
  23.      Add('JOBTYPE', ftString, 20, True);
  24.      Add('CLIENTID', ftSmallint, 4, True);
  25.      Add('PHOTOREPID', ftSmallint, 4, True);
  26.      Add('NOTES', ftMemo, 10, True)
  27.    end;
  28.  

1HuntnMan

  • Sr. Member
  • ****
  • Posts: 252
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
Re: TDBDateEdit component defaults to 12/30/1899
« Reply #3 on: September 11, 2024, 09:03:40 pm »
I tried recreating the Sales Orders table with Dates like so:
Code: Pascal  [Select][+][-]
  1. Add('ORDERDATE', ftDate, 0, False);
  2. Add('JOBCOMPLETED', ftDate, 0, False);
  3. Add('JOBDUEDATE', ftDate, 0, False);
  4.  

and then after Insert...
Code: Pascal  [Select][+][-]
  1. procedure TFrmSalesOrdersMgt.DbfSOAfterInsert(DataSet: TDataSet);
  2. begin
  3.   DataSet.FieldByName('ORDERDATE').Value:= Now;
  4.   DataSet.FieldByName('JOBDUEDATE').Value:= NULL;
  5.   DataSet.FieldByName('JOBCOMPLETED').Value:= NULL;
  6.   BitBtnSave.Enabled:= True;
  7.   BitBtnCancel.Enabled:= True;
  8.   JvDBLukUpCmboClient.SetFocus;
  9. end;
  10.  

This doesn't work either except filling the OrderDate with today's date.  The JOBDUEDATE and JOBCOMPLETED initialized as both as 12/30/1899.

I just chunked the TDBDateEdit components on the form and replaced with TJDBDateEdit and all is good!!!

BrunoK

  • Hero Member
  • *****
  • Posts: 589
  • Retired programmer
Re: TDBDateEdit component defaults to 12/30/1899
« Reply #4 on: September 11, 2024, 09:13:02 pm »

Code: Pascal  [Select][+][-]
  1. procedure TFrmSalesOrdersMgt.DbfSOAfterInsert(DataSet: TDataSet);
  2. begin
  3.   DataSet.FieldByName('ORDERDATE').Value:= Now;
  4.   DataSet.FieldByName('JOBDUEDATE').clear;
  5.   DataSet.FieldByName('JOBCOMPLETED').clear;
  6.   BitBtnSave.Enabled:= True;
  7.   BitBtnCancel.Enabled:= True;
  8.   JvDBLukUpCmboClient.SetFocus;
  9. end;
  10.  


1HuntnMan

  • Sr. Member
  • ****
  • Posts: 252
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
Re: TDBDateEdit component defaults to 12/30/1899
« Reply #5 on: September 11, 2024, 11:11:02 pm »
BrunoK, Okay, I'll try that because the TDBDateEdit allows me to format.  While I was typing this reply, tried your Now and Clear.  When the form appears these DBDateEdits still show  the 12/30/1899. When I insert, it corrects it, but the user is going to be confused when they bring up the form.  Now, this is the first record in the table.  I tried to put the Clears in the FormShow but that doesn't work.
So, I'm thinking I'll just stick with JDBDateEdit's  Thanks

wp

  • Hero Member
  • *****
  • Posts: 12364
Re: TDBDateEdit component defaults to 12/30/1899
« Reply #6 on: September 11, 2024, 11:56:30 pm »
And when you don't mention the empty data fields in the AfterInsert handler at all?

Code: Pascal  [Select][+][-]
  1. procedure TFrmSalesOrdersMgt.DbfSOAfterInsert(DataSet: TDataSet);
  2. begin
  3.   DataSet.FieldByName('ORDERDATE').Value:= Now;
  4. //  DataSet.FieldByName('JOBDUEDATE').clear;
  5. //  DataSet.FieldByName('JOBCOMPLETED').clear;
  6.   BitBtnSave.Enabled:= True;
  7.   BitBtnCancel.Enabled:= True;
  8.   JvDBLukUpCmboClient.SetFocus;
  9. end;
  10.  

 

TinyPortal © 2005-2018