TDateTime Problem - Programmers Heaven

Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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

  • pritaeaspritaeas Posts: 274Member
    : 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]
  • rajsharajsha Posts: 75Member
    : : 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.