John wrote:
> 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!!
>
>
> Has anybody any code to do a String-To-Date conversion using
> ShortDateFormat?
<PET-PEEVE>
The Delphi StrToDate function is a piece of crap. It forces the user to type
dates in the way the machine wants it and throws exceptions at the drop of a
hat.
I replaced it with a Str2Date function which has the code take what the user
types and determines a date from it if this can be done un-ambigously. It
doesn't care about seperators (they can be anything or missing),
alphanumeric vs numeric months, partial vs full years, or missing bits of
the date. All it needs to know is which order the date portions come in i.e.
DMY (UK), MDY (US) or YMD (ISO) date ordering which it parses out of the
ShortDateFormat.
I'm not especially fond of StrToFloat or StrToInt either. They were for the
high-jump as well.
</PET-PEEVE>
TTFN,
Paul.
---------------------------------------------------------------------------
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"