Solved

Format of DateTimeToStr

Posted on 1998-09-10
10
1,451 Views
Last Modified: 2012-05-05
How do I get the function DateTimeToStr to display the century
0
Comment
Question by:moonrise
  • 3
  • 3
  • 2
  • +1
10 Comments
 
LVL 2

Accepted Solution

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

Expert Comment

by:viktornet
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

by:moonrise
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

by:viktornet
ID: 1339343
How about this......

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

Regards,
Viktor Ivanov
0
 
LVL 10

Expert Comment

by:viktornet
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Expert Comment

by:kjteng
ID: 1339345
Just change the yyyy to yy in the DateTimeToString parameter
0
 
LVL 2

Expert Comment

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

Expert Comment

by:BlackDeath
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

by:moonrise
ID: 1339348
The function FormatDateTime is what I nedded. Thank you all.
0
 
LVL 1

Expert Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now