00 Votes

Delphi/Lazarus: Use Time-Constants in FormatDateTime Function as Text

Question by Guest | 2015-09-03 at 11:44

I am using the function FormatDateTime() in order to output a date and time formatted. This is working quite well, and it is even possible to use some other characters like a dot or a hyphen within the formatting string together with the characters standing for the time.

However, of course, this is only working when I am using characters or letters not having any special meaning within the format string. For example, whenever trying to write y, m, d, c, h, s or z, this character will be replaced with the corresponding time constant.

I would like to use some of those characters within my formatting string without having them replaced with the time value. Is there any possibility to do that? Up to now, I have tried to call FormatDateTime() for several times and to concate the resulting string with the characters having a special meaning. But this is quite cumbersome in the long run, so that I appreciate another method.

ReplyPositiveNegative
0Best Answer0 Votes

You can just surround the time constants that should not be replaced with quotation marks. In this case, they will not to be treated as constant. So, for example:

FormatDateTime('hh."hh."hh', now));

Here, the result would be something like "15.hh.15". As you can see, only the hs not standing within quotation marks will be replaced by the time. Because the dot is a character without special meaning, it does not matter whether this character is written within or outside of the quotation marks.
2015-09-03 at 15:55

ReplyPositive Negative
Reply

Related Topics

Delphi: System-Wide HotKey

Tutorial | 1 Comment

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.