set DBDateTimePicker empty

Posted on 2005-04-26
Last Modified: 2011-10-03
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 !!


Question by:sun4sunday
    LVL 15

    Assisted Solution

    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);
      // set format to whatever you want
      label1.Caption := FormatDateTime('dd/mm/yyyy hh:nn:ss', DateTimePicker1.DateTime);
    LVL 15

    Expert Comment

    Also you can put a button or a popup menu for the label to clear the caption, i.e. clear the date.
    LVL 15

    Expert Comment

    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.
    LVL 27

    Accepted Solution

    well, this is really annoying of the standard dbdatetimepicker,

    but you can replace it with another thirdparty-component

    there are some for free

    meikl ;-)
    LVL 15

    Expert Comment

    I totally agree Kretzschmar.
    LVL 26

    Expert Comment

    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);
      // 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''';

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Suggested Solutions

    A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
    Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now