?
Solved

Format of DateTimeToStr

Posted on 1998-09-10
10
Medium Priority
?
1,488 Views
Last Modified: 2012-05-05
How do I get the function DateTimeToStr to display the century
0
Comment
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
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
10 Comments
 
LVL 2

Accepted Solution

by:
kjteng earned 40 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
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.

 
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
 
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

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!

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month9 days, 23 hours left to enroll

762 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