Delphi and Kylix

Moderators: pritaeas
Number of threads: 7244
Number of posts: 19051

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
TDateTime Problem Posted by Chaitanya_Pune on 31 Aug 2005 at 4:39 AM
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?
Report
Re: TDateTime Problem Posted by pritaeas on 31 Aug 2005 at 8:40 AM
: 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);

Report
Re: TDateTime Problem Posted by rajsha on 2 Sept 2005 at 11:02 AM
: : 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.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.