[fpc-pascal] date formating dificulty

Philippe philippe at quarta.com.br
Wed Nov 19 20:45:48 CET 2014


 

Em 19.11.2014 12:17, Philippe escreveu: 

> Em 18.11.2014 10:27,
Michael Van Canneyt escreveu: 
> 
>> On Tue, 18 Nov 2014, Philippe
wrote:
>> 
>>> Em 18.11.2014 09:49, Philippe escreveu: I wrote a
program: - windows 8 32 bits - lazarus 1.2.4 ... fpc 2.6.4 then I copied
it to another computer - windows 7 64 bits - lazarus 1.0.14 .... fpc
2.6.2 and got into trouble with dates format! programs behave diferent
way, and what was working on the fisrt computer does not work properly
in the second! I guess I need some tutorial (I looked for but did not
find anything :( !) why formatDateTime( 'DD/MM/YYYY', now) returns
18-11-2014 and not 18/11/2014 ? strtodate( formatDateTime( 'DD/MM/YYYY',
now)) works ok on the w 8 32 bits, but arise an exception on the w 7 64
bits. I am confused with the following syntax function FormatDateTime(
const FormatStr: string; DateTime: TDateTime; const FormatSettings:
TFormatSettings ):string; how does it work between two format
especifications: FormatStr and FormatSettings ? appreciate any example
of good programming pratise of data formating to avoid bad surprise
moving program from an OS to another ! Philippe on
http://www.freepascal.org/docs-html/rtl/sysutils/strtodate.html [1] I
found Program Example19; { This program demonstrates the StrToDate
function } Uses sysutils; Procedure TestStr (S : String); begin Writeln
(S,' : ',DateToStr(StrToDate(S))); end; Begin Writeln ('ShortDateFormat
',ShortDateFormat); TestStr(DateTimeToStr(Date));
TestStr('05'+DateSeparator+'05'+DateSeparator+'1999');
TestStr('5'+DateSeparator+'5'); TestStr('5'); End. the compiler warns
that ShortDateFormat is deprecated ... which is not informed in the doc
...
>> 
>> It should be, I will check.
>> 
>> Anyway, as Graeme hinted:
ShortDateFormat contains a format string, and / is a placeholder for the
date 
>> separator character on the computer on which the program is
running.
>> 
>> If you want to force a character, you can enclose it in
quotes:
>> ShortDateFormat:='dd"/"mm"/"yyyy'
>> will always use / as the
date separator, no matter what the internatonalization settings on the
PC.
>> 
>> But it is bad practice to do so.
>> 
>> Secondly, it is a
common mistake to think that StrToDate will always correctly perform the
opposite of DateToStr.
>> It does not, but this is documented.
>> 
>>
Michael.
>> 
>> I still don't know how to use at the same time formatStr
and FormatSettings in FormatDateTime.
>> 
>> I´ll like very much to find
a tutorial or some example about the good practice to manage dates and
be sure it will do the same thing on different machines ....
>> 
>>
Thanks
>> 
>> interesting stuff ... but ... out of date!!!! using
deprecatings ... (from year 2000 !!!) ... does not help much!!!
>> 
>>
http://www.math.uni-leipzig.de/pool/tuts/FreePascal/units/node21.html#SECTION002141000000000000000
>>

>> _______________________________________________
>> fpc-pascal
maillist - fpc-pascal at lists.freepascal.org
>>
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal [2]
> 
>
_______________________________________________
> fpc-pascal maillist -
fpc-pascal at lists.freepascal.org
>
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal [2]




Links:
------
[1]
http://www.freepascal.org/docs-html/rtl/sysutils/strtodate.html
[2]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20141119/b822ac01/attachment.html>


More information about the fpc-pascal mailing list