TDateTime Problem

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?

Comments

  • : 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:

    [code]
    sSelectedDate := FormatDateTime('YY/MM/DD',now);
    dtSelectedDate := StrToDateTime(sSelectedDate);
    [/code]
  • : : 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:
    :
    : [code]
    : sSelectedDate := FormatDateTime('YY/MM/DD',now);
    : dtSelectedDate := StrToDateTime(sSelectedDate);
    : [/code]
    :

    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:

    [Code]
    Var
    CDay,CMonth,CYear : Word;
    begin
    DecodeDate(Date,CYear,CMonth,CDay);
    [/Code]
    The decoded values can then be used in strings etc.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories