Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2012-02

FormatDatetime is not respecting the specified pattern

6 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Luciano de Souza

Hello listers,

A strange error came up when formating a date. See this code: writeln(formatdatetime('dd/mm/YYYY', now));
The answer should be: 31/01/2012
The answer was: 31-01-2012
I did one test else:
writeln(formatdatetime('dd$mm$YYYY', now));
The answer was: 31$01$2012
Yes, the problem seems to be related to the backslash. DefaultFormatSettings.DateSeparator := '/';
writeln(formatdatetime('dd/mm/YYYY', now));
The answer was: 31/01/2012
Right! That's the answer. But it was necessary to setup the settings manually.
The test was done with Freepascal 2.4.4 and Ubuntu 10.10. Does someone know what is my mistake?
Regards,
Luciano

Reply by email

waldo kitty
to Luciano de Souza
Luciano de Souza wrote 10 lines
Hello listers, A strange error came up when formating a date. See this code: writeln(formatdatetime('dd/mm/YYYY', now)); The answer should be: 31/01/2012 The answer was: 31-01-2012 I did one test else: writeln(formatdatetime('dd$mm$YYYY', now)); The answer was: 31$01$2012 Yes, the problem seems to be related to the backslash.

errrm1... that's not a 'back slash'... that's a "forward" slash.. aka just a plain slash... "back slash" leans backwards (ie: top to the left)...

Show quoted text 5 lines
DefaultFormatSettings.DateSeparator := '/'; writeln(formatdatetime('dd/mm/YYYY', now)); The answer was: 31/01/2012 Right! That's the answer. But it was necessary to setup the settings manually. The test was done with Freepascal 2.4.4

errrm2: FP 2.6.0 is the current release... unless i'm highly mistaken... but still, see higher above ;)

Reply by email

Michael Van Canneyt
to Luciano de Souza: A strange error came up when formating a date. See this code:…
Luciano de Souza wrote 16 lines
    Hello listers,  A strange error came up when formating a date. See this code: writeln(formatdatetime('dd/mm/YYYY', now)); The answer should be: 31/01/2012 The answer was: 31-01-2012 I did one test else: writeln(formatdatetime('dd$mm$YYYY', now)); The answer was: 31$01$2012 Yes, the problem seems to be related to the backslash. DefaultFormatSettings.DateSeparator := '/'; writeln(formatdatetime('dd/mm/YYYY', now)); The answer was: 31/01/2012 Right! That's the answer. But it was necessary to setup the settings manually. The test was done with Freepascal 2.4.4 and Ubuntu 10.10. Does someone know what is my mistake?

There is no mistake, all is as it should be.

In the format string for FormatDateTime, a / means 'use the date separator of the RTL'.

By default, on linux the RTL date separator is the '-' character.

If you want to initialize the RTL locale settings with the system settings, just put 'clocale' as one of the first units in your uses clause. It will set all necessary constants.

if you want an actual / character in your output, you should do a

writeln(formatdatetime('dd"/"mm"/"YYYY', now));

i.e. enclose the special character in double quotes.

Michael.

Reply by email

silvioprog
to Michael Van Canneyt

2012/2/1 Michael Van Canneyt :

Show quoted text 37 lines
On Wed, 1 Feb 2012, Luciano de Souza wrote: >     Hello listers, > >  A strange error came up when formating a date. See this code: > writeln(formatdatetime('dd/mm/YYYY', now)); > The answer should be: 31/01/2012 > The answer was: 31-01-2012 > I did one test else: > writeln(formatdatetime('dd$mm$YYYY', now)); > The answer was: 31$01$2012 > Yes, the problem seems to be related to the backslash. > DefaultFormatSettings.DateSeparator := '/'; > writeln(formatdatetime('dd/mm/YYYY', now)); > The answer was: 31/01/2012 > Right! That's the answer. But it was necessary to setup the settings > manually. > The test was done with Freepascal 2.4.4 and Ubuntu 10.10. > Does someone know what is my mistake? There is no mistake, all is as it should be. In the format string for FormatDateTime, a / means 'use the date separator of the RTL'. By default, on linux the RTL date separator is the '-' character. If you want to initialize the RTL locale settings with the system settings, just put 'clocale' as one of the first units in your uses clause. It will set all necessary constants. if you want an actual / character in your output, you should do a writeln(formatdatetime('dd"/"mm"/"YYYY', now)); i.e. enclose the special character in double quotes. Michael.

o.o'

Very nice explanation. Thank you! :)

Silvio Clécio ==================================== Site - <silvioprog.com.br> LazSolutions - <code.google.com/p/lazsolutions> ====================================

Reply by email

Luciano de Souza
to waldo kitty: errrm1... that's not a 'back slash'... that's a "forward" slash.. aka just a plain…

Oh! Your correction is really good and welcome. Becouse of a Leber Congenital Amaurosis, I became blind when I was a child. As a consequence, nowadays, for me, slashes and backslashes are only a word spoken by the screen reader. It's really curious how brains can work differrently.

When people know you are blind, they don't use to make this kind of comment. I am lucky becouse you don't know it! Yes, if the shape of slashes and backslashes were similar to a triangle or a castle, it wouldn't matter for my daily life. In spite of this, it's really intersting to know how things exist in the visual world.

Even screen readers are worried in supplying some visual information. NVDA, the screen reader I currently use, can speak the RGB code on a particular point. Other screen readers can be more: they can also speak the name of the color. Some time ago, using this feature, I knew a color called "brick". Brick as a color? It's really intersting. Yes, this information is not very important in my life, but at the point of view of culture, of the visual culture, it's really curious.

For these reasons, I like Pascal intensively. The two first screen readers, these technological wonder, I have been using, they are developed in Pascal: Dosvox and Virtual Vision, both conceived by brazilian developers.

Welll, well, let me stop the message. If I say something more off topic, I will be likely talking about planets and galaxes!

Thank you very much!

Regards,

Luciano

waldo kitty wrote 30 lines
On 1/31/2012 22:23, Luciano de Souza wrote: > Hello listers, > > A strange error came up when formating a date. See this code: > writeln(formatdatetime('dd/mm/YYYY', now)); > The answer should be: 31/01/2012 > The answer was: 31-01-2012 > I did one test else: > writeln(formatdatetime('dd$mm$YYYY', now)); > The answer was: 31$01$2012 > Yes, the problem seems to be related to the backslash. errrm1... that's not a 'back slash'... that's a "forward" slash.. aka just a plain slash... "back slash" leans backwards (ie: top to the left)... > DefaultFormatSettings.DateSeparator := '/'; > writeln(formatdatetime('dd/mm/YYYY', now)); > The answer was: 31/01/2012 > Right! That's the answer. But it was necessary to setup the settings > manually. > The test was done with Freepascal 2.4.4 errrm2: FP 2.6.0 is the current release... unless i'm highly mistaken... but still, see higher above ;) _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Luciano de Souza

Reply by email

Luciano de Souza
to waldo kitty: errrm1... that's not a 'back slash'... that's a "forward" slash.. aka just a plain…

Oh! Very well! I am blind, for me, slashes and backslashes are only words spoken by the screen reader. The worst is I listen "barra" and "barra invertida", the portuguese correspondent words. You can imagine: I don't see slashes and I listen differently. The chance of mistake is very high! But fortunately, I have a good friend who corrects me! One bilion of corrections else and I will be perfect!

Thank you very much!

waldo kitty wrote 30 lines
On 1/31/2012 22:23, Luciano de Souza wrote: > Hello listers, > > A strange error came up when formating a date. See this code: > writeln(formatdatetime('dd/mm/YYYY', now)); > The answer should be: 31/01/2012 > The answer was: 31-01-2012 > I did one test else: > writeln(formatdatetime('dd$mm$YYYY', now)); > The answer was: 31$01$2012 > Yes, the problem seems to be related to the backslash. errrm1... that's not a 'back slash'... that's a "forward" slash.. aka just a plain slash... "back slash" leans backwards (ie: top to the left)... > DefaultFormatSettings.DateSeparator := '/'; > writeln(formatdatetime('dd/mm/YYYY', now)); > The answer was: 31/01/2012 > Right! That's the answer. But it was necessary to setup the settings > manually. > The test was done with Freepascal 2.4.4 errrm2: FP 2.6.0 is the current release... unless i'm highly mistaken... but still, see higher above ;) _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email