Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

display MySQL date field in DBaware components

Status
Not open for further replies.

bowens44

Programmer
Jan 29, 2009
10
US
I am using Delphi 6. I am rather new to this.

Whenever an empty MySQL date field (not really empty but 000-00-00) is displayed in db-aware controls (dbgrid and dbedit), it is displayed as '12/30/1899'. Is there way to make the controls display and empty/blank field instead of 12/30/1899 ?
 
dates are stored as the number of days since 12/30/1899.... today is 39904...
i guess you could do something in your query to make the results null....

Code:
SELECT Case WHEN DateField = 0 then NULL else Datefield END as RealDate FROM TableName

Leslie

Have you met Hardy Heron?
 
You can also make use of the OnGetText and OnSetText methods of the TField object.

The following was pulled from:

Handling Null values with Field Events

The OnGetText and OnSetText events, can be used to customize the output of a field. These two(2) events are extremely powerful: they allow you to use data-aware controls even when the representation of a field you want to display is different from the one Delphi will provide by default.

procedure TForm1.Table1ShipDateGetText
(Sender: TField;
var
Text: string;
DisplayText: boolean);
begin
if Sender.IsNull then
Text := '<undefined>'
else
Text := Sender.AsString;
end;

procedure TForm1.Table1ShipDateSetText
(Sender: TField; const Text: string);

begin
if Text = '' then
Sender.Clear
else
Sender.AsString := Text;
end;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top