: : Problem occurs only when I change the 'Short Date' format in the Regional Setting in Control Panel from 'dd/mmm/yy' to anything else.
: : ---------------------------------------------------------------
: : procedure TfrmComp.FormActivate(Sender: TObject);
: : var
: : sSelectedDate : String;
: : dtSelectedDate : TDateTime;
: : begin
: :
: : sSelectedDate := FormatDateTime('dd/mm/yyyy',now);
: :
: : // Runtime exception occurs at the followin line
: : // stating EConverError '31/08/2005' is not a valid date
: :
: : dtSelectedDate := StrToDateTime(sSelectedDate);
: :
: : End;
: : ------------------------------------------------------------------------
: : Can anyone help?
: :
:
: According to the help file (I'm using D5) StrToDateTime NEEDS the YY/MM/DD format... This should therefor work:
:
:
: sSelectedDate := FormatDateTime('YY/MM/DD',now);
: dtSelectedDate := StrToDateTime(sSelectedDate);
:
:
Can first the YY,MM,DD values be extracted from the date and then used in whatever way. In this way date formats or control panel settings will be taken care of:
Var
CDay,CMonth,CYear : Word;
begin
DecodeDate(Date,CYear,CMonth,CDay);
The decoded values can then be used in strings etc.