On Tue, 20 Oct 2009, Graeme Geldenhuys wrote:

On 20/10/2009, Graeme Geldenhuys <graemeg.li...@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!

But perfectly documented...

I agree that it is tricky. I often had to correct code from people who
didn't understand this and inserted some kind of formatdatetime('mm/dd/yyy')
in an SQL statement and were surprised to see '04 09 2005' in their SQL,
which of course generated an error.

Michael.
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to