Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# Format of DateTimeToStr

Posted on 1998-09-10
Medium Priority
1,500 Views
How do I get the function DateTimeToStr to display the century
0
Question by:moonrise
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 3
• 3
• 2
• +1

LVL 2

Accepted Solution

kjteng earned 40 total points
ID: 1339340
DateTimeToString( s, 'yyyy', dateValue);
s := Copy(s, 1,2);
0

LVL 10

Expert Comment

ID: 1339341
Why not just use the year to find the century????

function GetCentury(Year : Integer):Integer;
begin
Result := StrToInt(Copy(IntToStr(Year), 1, 2)) + 1;
end;

Example Call:  Caption := IntToStr(GetCentury(1998));
//will return 20th century

Regards,
Viktor Ivanov
0

Author Comment

ID: 1339342
Sorry, I guess my question was not clear.  What I meant was that when I use the function DateTimeToStr, the returned string displays the year as 98, not 1998.  Thank you.
0

LVL 10

Expert Comment

ID: 1339343

Caption :=  DateTimeToStr(Now);//this function uses only one parameter

Regards,
Viktor Ivanov
0

LVL 10

Expert Comment

ID: 1339344
You could also use....

var
s : string;
begin
DateTimeToString(s, 'yy', Now);//returns 98 instead of 1998
caption := s;
end;

Regards,
Viktor Ivanov
0

LVL 2

Expert Comment

ID: 1339345
Just change the yyyy to yy in the DateTimeToString parameter
0

LVL 2

Expert Comment

ID: 1339346
ie DateTimeToString(s, 'dd-mm-yy', dateValue)
0

LVL 1

Expert Comment

ID: 1339347
nope. i think, the problem is the other way round.
he gets 98 and wants 1998.
right?

S := FormatDateTime('dd.mm.yyyy', Now); or
DateTimeToString(S, 'dd.mm.yyyy', Now);

problem is the system's setting of displaying the year is relevant when using DateTimeToStr.

Black Death.
0

Author Comment

ID: 1339348
The function FormatDateTime is what I nedded. Thank you all.
0

LVL 1

Expert Comment

ID: 1339349
no prob. cheerio,
Black Death.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi projâ€¦
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy reâ€¦
Please read the paragraph below before following the instructions in the video â€” there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, â€¦