• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1150
  • Last Modified:

set DBDateTimePicker empty

I am using Delphi5 and SQL Server.
I am connected a table field with a DBDateTimePicker.
When the table is in the insert mode the DBDateTimePicker shows default value like 01/01/1900.
i want to set the DBDateTimePicker as EMPTY. When the user select a date, then only it should get filled by date.

Some cases the users will not fill the date also. Then it should post null vaule to the table.

Experts help me !!

sun4sunday

0
sun4sunday
Asked:
sun4sunday
  • 4
2 Solutions
 
mikelittlewoodCommented:
This cant be done, it must have some date in there.
The workaround for this is to use a label with the datetimepicker

Make the label the same height as the datetimepicker, and just a little shorter. Shrink the datetimepicker down to just the arrow and place next to the label.
Then when you select the datetime from the picker, use the OnClose event to populate the label with the datetime

procedure TForm1.DateTimePicker1CloseUp(Sender: TObject);
begin
  // set format to whatever you want
  label1.Caption := FormatDateTime('dd/mm/yyyy hh:nn:ss', DateTimePicker1.DateTime);
end;
0
 
mikelittlewoodCommented:
Also you can put a button or a popup menu for the label to clear the caption, i.e. clear the date.
0
 
mikelittlewoodCommented:
When you then post to the database, you just need to check that the caption of the label is empty. If it is then save NULL to the database rather than the value in the datetimepicker.
0
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!

 
kretzschmarCommented:
well, this is really annoying of the standard dbdatetimepicker,

but you can replace it with another thirdparty-component
see
http://www.torry.net/pages.php?id=526

there are some for free

meikl ;-)
0
 
mikelittlewoodCommented:
I totally agree Kretzschmar.
0
 
Eddie ShipmanAll-around developerCommented:
I can not find a DBDateTimePicker in my Delphi6, is this a 3rd party control?
If so, whose is it?

I can make the DateTimePicker show what I want like this:

procedure TForm1.DateTimePicker1Change(Sender: TObject);
begin
  // Change the Format if this Date is not 0 and
  // the Format is already '''Chose a date'''
  if (TDateTimePicker(Sender).Format = '''Choose a date''') and
     (Trunc(DateTimePicker1.Date) <> 0 )then
    TDateTimePicker(Sender).Format := ShortDateFormat;

  // if the date is 0 then set the Format to '''Chose a date'''
  if Trunc(DateTimePicker1.Date) = 0 then
    DateTimePicker1.Format := '''Choose a date''';
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  // Here, we are setting it's date to 0 so we can use the
  // Format property to show what we want.
  DateTimePicker1.Date := 0;
  DateTimePicker1Change(DateTimePicker1);
end;
0

Featured Post

Independent Software Vendors: 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!

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