Jump to content
Squall_FF8

MS SQL, How to make a TfdQuerry returns Date in a specific format?

Recommended Posts

Hey guys,
I have old MS SQL 2008 and a Query (FireDAC), that returns some fields in Date format. In a Delphi application all work great, it seems FireDac takes care to visualize Date to FormatSettings.

However when I open a FastReport document, it seems it convert Date to a the PC local settings (different from my changes in FormatSettings). And that is not good, because on different machines, results could look differently.

I wonder, is there a way, to force Dates in FastReport to be in my desired format regardless of the PC local? 
A possible solution, could be if I force the Query to return the desired format, I just wonder how?

Share this post


Link to post

Good old Convert ...

 

I'm wondering is there more convenient way - to set format per session, like in Oracle (you set some local settings only for "your" session).
The reason is that I have tables with 20+ fields (at least 6 are in date format) and that will make huge Select statements. 

Share this post


Link to post

Can't you create a view that do the convert for you, so that you don't have to fiddle with the conversions in that SQL?

Share this post


Link to post
Posted (edited)

Add a BeforePrint handler to the memo control. Make sure that you clear the DataField and DataSet properties of the memo control or BeforePrint won't have any effect..

 

procedure Memo13OnBeforePrint(Sender: TfrxComponent);
begin
  TfrxMemoView(Sender).Text := FormatDateTime('yyyy-mm-dd', <Ticket."ticket_date">);                                                                            
end;

 

No formatting:

image.png.e13788e7d43cf9937a112687c8429c20.png

 

With the BeforePrint:

image.png.1a91fea5d50cc0e4c432e576832f6e91.png

Edited by weirdo12
  • Like 1

Share this post


Link to post
Posted (edited)

@weirdo12 Great example and practical illustration!!!
May we adapt it, if the text is in RichView (instead of Memo) and it is more complicated, like:

xxxxx  [Ticket."ticket_date"]  xxxxxx

 

Edited by Squall_FF8

Share this post


Link to post
8 minutes ago, Squall_FF8 said:

May we adapt it, if the text is in RichView (instead of Memo) and it is more complicated, like:


xxxxx  [Ticket."ticket_date"]  xxxxxx

 

If you double-click the RichView component is there a Format tab? If so, look in expressions and pick your date/time column and set the format string there. If the RichView contains multiple columns, each one will be listed in Expressions.

 

image.thumb.png.dc5a8c13633357f1e0a1d0eb31f7d3ac.png 

Share this post


Link to post
On 8/29/2025 at 7:11 PM, weirdo12 said:

If you double-click the RichView component is there a Format tab?

Not in RichText:
image.thumb.png.d026279faefe83df3c043baa6231d3b9.png

Share this post


Link to post

Try adding a variable. I included a bunch of screen shots because it's not exactly obvious that you have to create a new Category before you can create a variable.

 

image.png.fe99d692ea8d17be46fd2a19796ca442.png

 

Then add a Category:

 

image.png.4035261ba36fa5328e71f5d144d0a121.png

 

Select the Category and click Variable and assign it a value:

 

image.thumb.png.2d3375cf71dd3a9024965cdd025bcbea.png

 

Close Edit Variables. Now you *should* be able to drop that variable into the Rich Edit control.

 

image.png.750cf6d9c6164b3d23b0029dbd5326ac.png

 

image.png

image.png

Edited by weirdo12

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×