[fpc-pascal] Why has StrToDate() failing under FPC 2.3.1 (64bit)

Graeme Geldenhuys graemeg.lists at gmail.com
Tue Oct 20 13:16:37 CEST 2009


On 20/10/2009, Graeme Geldenhuys <graemeg.lists at gmail.com> wrote:
>  PS:
>  Oh and a nice hidden little features (I couldn't find documentation
>  for). When you specify a date format as 'yyyy/mm/dd' or dd/mm/yy
>  etc... The '/' character is NOT the separator!


Correction, that applies to FormateDateTime(), not StrToDate(). I got
a bit confused.

Here is an example of what I meant:

-----------------------------
procedure TestDate(S: string);
begin
 writeln(s + ' formatting  => ' + FormatDateTime(s, Date));
end;

begin
 DateSeparator := '?';  // force separator to ? character

 Writeln('DateSeparator = ', DateSeparator);
 Writeln('-------');
 TestDate('yyyy-mm-dd');
 TestDate('yyyy~mm~dd');
 TestDate('yyyy/mm/dd');
 TestDate('yyyy''/''mm''/''dd');
end.

-----------------------------

And here follows the output:


c:\temp>project1
DateSeparator = ?
-------
yyyy-mm-dd formatting  => 2009-10-20
yyyy~mm~dd formatting  => 2009~10~20
yyyy/mm/dd formatting  => 2009?10?20
yyyy'/'mm'/'dd formatting  => 2009/10/20


As you can see. If you want to force '/' as your date delimiter,
irrespective to what DateSeparator is set at, you have to place the
the '/' in qoutes so it doesn't get interpreted as a place-holder for
DateSeparator. Sneaky code!



-- 
Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/



More information about the fpc-pascal mailing list