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.
4 Answers
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;

- 134,889
- 20
- 356
- 483
-
2Thanks, this works perfectly. I use the single space to suppress any display and an empty string (no space) to set it back to the default format. – Larry Lustig Nov 20 '10 at 19:28
-
7Does that still work for allowing the user to enter a date with the keyboard? – Rob Kennedy Nov 21 '10 at 07:06
You could also try:
DateTimePicker1.Format := '__/__/____';
That way it looks to the end user like a date is required.

- 76,112
- 17
- 94
- 154

- 21
- 2
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.

- 1,620
- 1
- 20
- 46
In Delphi 10 the way to enable the TDateTimePicker again is:
DateTimePicker1.format := EmptyStr;
The ShortDateFormat is no more present in system.SysUtils

- 77
- 10
-
`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