Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1507
  • Last Modified:

Format of DateTimeToStr

How do I get the function DateTimeToStr to display the century
0
moonrise
Asked:
moonrise
  • 3
  • 3
  • 2
  • +1
1 Solution
 
kjtengCommented:
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now