Format of DateTimeToStr

How do I get the function DateTimeToStr to display the century
moonriseAsked:
Who is Participating?
 
kjtengConnect With a Mentor Commented:
DateTimeToString( s, 'yyyy', dateValue);
s := Copy(s, 1,2);
0
 
viktornetCommented:
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
 
moonriseAuthor Commented:
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
viktornetCommented:
How about this......

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

Regards,
Viktor Ivanov
0
 
viktornetCommented:
You could also use....

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

Regards,
Viktor Ivanov
0
 
kjtengCommented:
Just change the yyyy to yy in the DateTimeToString parameter
0
 
kjtengCommented:
ie DateTimeToString(s, 'dd-mm-yy', dateValue)
0
 
BlackDeathCommented:
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
 
moonriseAuthor Commented:
The function FormatDateTime is what I nedded. Thank you all.
0
 
BlackDeathCommented:
no prob. cheerio,
Black Death.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.