16

How can I show an "empty" TDateTimePicker in Delphi 2010 (that is, hide the display of the date so the control appears empty). I know about the trick of setting the format to show the epoch, but with Delphi 2010 running on Windows 7 the string "A.D." appears in the control when I do this.

Larry Lustig
  • 49,320
  • 14
  • 110
  • 160

4 Answers4

19

try setting the format to a blank space Value.

DateTimePicker1.Format:=' ';

and then in the OnChange method set the format again

procedure TForm1.DateTimePicker1Change(Sender: TObject);
begin
DateTimePicker1.Format:=ShortDateFormat;
end;
RRUZ
  • 134,889
  • 20
  • 356
  • 483
2

You could also try:

DateTimePicker1.Format := '__/__/____';

That way it looks to the end user like a date is required.

Andriy M
  • 76,112
  • 17
  • 94
  • 154
1

I came across this question when looking to see how to handle this.

I'm actually using a TJvDateTimePicker primarily because it displays week numbers in the drop down. I was going to use the 'format trick' suggested by @RRUZ, but have found that the TJvDateTimePicker includes a couple of extra published properties, NullDate and NullText which are used to implement the "format trick".

In my form's constructor I place the code:

dtpOne.NullDate := 0;
dtpOne.NullText := ' '; // empty string doesn't work

All seems to work as you'd expect.

Michael Vincent
  • 1,620
  • 1
  • 20
  • 46
0

In Delphi 10 the way to enable the TDateTimePicker again is:

DateTimePicker1.format := EmptyStr;

The ShortDateFormat is no more present in system.SysUtils

  • `ShortDateFormat` together with other format settings were earlier (e.g. Delphi 7) global variables in the `SysUtils` unit. Now they are fields of a global `TFormatSettings` record, called `FormatSettings`. IOW, to use the globally declared `ShortDateFormat` you must write `FormatSettings.ShortDateFormat`. – Tom Brunberg Feb 27 '22 at 07:41