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

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

@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

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

×