John,
try
StringToDateTime(FormatDateTime('dd-mm-yyyy', Now));
In order to use your original format, you might want to check the
values some of the system variables, such as ShortDateFormat, at
the point your code is failing.
Cheers.
John Christenhusz wrote:
>
> Hi all,
>
> Who knows the answer to this simple problem?
>
> DateToStr(now) returns nicely the string equivalent for the current date
> using ShortDateFormat.
>
> StrToDate('<date string>') returns the TDateTime for the given date string.
> However, when you have the date time settings so that you use e.g.
> '25-Oct-2000', thus the ShortDateFormat = 'dd-MMM-yyyy' then it falls over.
>
> The help on StrToDate says "ShortDateFormat global variable--possible
> combinations are m/d/y, d/m/y, and y/m/d".
> This implies (to my opinion) that StrToDate is not using the
> ShortDateFormat !
>
> Eg. (using ShortDateFormat = 'dd-MMM-yyyy' )
> DateToStr(now) returns nicely '25-Oct-2000'
> but StrToDate needs '25-10-2000'
>
> and so StrToDate( DateToStr(now) ) does not work!!
How about using just:
now; // ;-)
>
> Has anybody any code to do a String-To-Date conversion using
> ShortDateFormat?
>
> Thanks a lot for any help.
>
> John.
>
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"