Go Premium for a chance to win a PS4. Enter to Win

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

How can I get the year as a four-digit number in QuickRep?

I am using D3 and QR2.0K for D3. In my delphi project, I linked the report to TQuery component, I used the TQRExpr component to display/print the year, the TQRExpr component Expression property is [RepDate].

The TQRExpr component just can show the year as a two-digit number. How can I get the year as a four-digit number?


I have another question, please look at http://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=10302123 

Regards, supwang
0
SupWang
Asked:
SupWang
  • 3
  • 2
1 Solution
 
simonetCommented:
The trick is to, right before issueing the QuickRep.Preview method, set the ShortDateFormat global variable to something like

ShortDateFormat := 'dd/MM/yyyy';

Then after the report is through, change ShortDateFormat back to its original state (which you save on another string variable).

The reason this trick works is because the TQRExpr component uses Delphi's built-in date and string handling routines, which, in turn, rely on the ShortDateFormat variables, which you can change at will, without messing up with the computer's system-wide config.

Yours,

Alex
0
 
simonetCommented:
Another option is to change the value that the TQRExpr prints right before it gets printed:

procedure TForm1.QRExpr1Print(sender: TObject; var Value: String);
begin
   Value := FormatDateTime('mm/dd/yyyy', StrToDate(Value));
end;

The above will read the Value variable, change it to Date and then Change it back to a String, however using 4 digits for the year.

Although this works, the first method I outlined is a cleaner way to have it working.

You can always, of course, go to the  Control Panel and change the short date format to a 4-digit year format.

Yours,

Alex

0
 
SupWangAuthor Commented:
Hi Alex,
Thanks.
I like the first way. I also know the second, but I don't want to use it.
I can't find the help of "ShortDateFormat" in D3, But find it in D4. :-)
How do you handle the display format of the year? I want to set all the date to yyyy-m-d in
the program start-up, How do you think about it?

and Please look at my new question:
http://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=10308596 

Regards, supwang
0
 
simonetCommented:
I usually change ShortDateFormat in the project source (the .DPR file), so it's consistent along the whole program.

I warn you not to change the date format to unusual formats, because that may confuse your users (they may not be used to the format you're suggesting), but that's entirely up to you.

Alex
0
 
SupWangAuthor Commented:
Alex, Have you see my another question? need your help.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

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