Author: Jeff Guidotti
Here is a working example of how to use alternative date formats in the
TDateTimePicker component for Delphi 5.
Answer:
The problem for me with the TDateTimePicker component, is that it would not only
allow dates based on the Windows settings for ShortDate and LongDate, but it also
left gaps in between the separators for dates like ' 2/ 3/01'. This made it look
terrible.
I did some research into the problem, and found many "solutions" that did not seem
to work all the time. So far, I haven't had any problems with this one, and
although I tested it in Delphi 5, it should work in some previous versions.
Simply enter the following line of code into the OnActivate Event for each
TDateTimePicker on your form. This will manually set the format, and it should
remain in place until the form is destroyed.
1 2 DateTimePicker1.Perform(DTM_SETFORMAT, 0, DWORD(PCHAR('MM/dd/yyyy')));
The above example assumes that the TDateTimePicker is named DateTimePicker1, and
you can vary the format by changing the format string ('MM/dd/yyyy').
I am not sure what format's are available, and it seems a bit quirky. I had tried to use 'mm/dd/yyyy', and I wound up with a month of '52'!!! The above string forces two digit months and days, and four-digit years.