Delphi TDateTimePicker date format

 

Posted by webmaster Guido on January 14, 2003

In Reply to: Dates posted by Ste D on January 07, 2003

: Is their any way to change the date format in a datetimepicker to english insted of american? i.e. 13th of jan would be 13/01/03 in english in american = 01/13/02 any suggestions?

 

Delphi's TDateTimePicker is a wrapper around a Microsoft control. It allows you to show the date in one of two formats (long and short), but in Delphi 5 and lower it did not allow you to change the date nor the time format. That's because it uses the Windows date and time settings, not Delphi's internal format variables like "ShortDateFormat".

In D6 and later, you can use the Format property to change the display of date or time.

In D5 and earlier, use the DateTime_SetFormat call, as shown below. You'll have to add "CommCtrl" to the "USES" directive in the beginning of the unit, otherwise DateTime_SetFormat won't be recognized:

uses Windows, Messages, ..., COMMCTRL;

Next, put this in the FormCreate event handler:

DateTime_SetFormat(DateTimePicker1.Handle, PChar('MM/dd/yyyy'));

(attention: the 'MM' is in uppercase, 'mm' does not work)

 


[ DelphiLand Discussion Forum ]