Solved

Format of DateTimeToStr

Posted on 1998-09-10
10
1,455 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

773 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