Home End User
New Blog Posts: Merging Reports - Part 1 and Part 2

DateTime formats

edited April 2004 in End User
What is the best way to deal with datetime formats in distributed reports?
I want the default format the datetime fields to lose the unsightly
'seconds' portion, something like ShortDateFormat+ '@' + ShortTimeFormat.
I have used two unsatisfactory methods in the past:

1) I would set it with RAP, and I had a passthrough function to do the
job; but this overrides what the user may set in the Designer's
DisplayFormat options, and I don't want to have to force the user to have
a Calc tab to remove the code

2) I registered my own formatting entries for the Designer with

gcDisplayFormat := TmyDisplayFormat;

my key code being:

...
dtDateTime:
begin
aFormatList.Add('Short Date' + #1 + ShortDateFormat);
aFormatList.Add('Short DateTime' + #1 + ShortDateFormat + ' @ '
+ShortTimeFormat);
aFormatList.Add('Long Date' + #1 + LongDateFormat) ;
aFormatList.Add('Long DateTime' + #1 + LongDateFormat + ' @ '
+ LongTimeFormat) ;

...etc

But of course this just puts in my locale's formats when I am designing
reports. And again I don't want to force the user to have to correct this.

Is there a better way?

TIA

Paul

Comments

  • edited April 2004
    "Paul Toms" wrote in message
  • edited April 2004

    I might be misunderstanding but I think what you need is for the
    GetDisplayFormat strings to indicate whether to use the current locale (or
    perhaps you want them all to work in this manner).

    The TmyDisplayFormat.Format method that applies the format pattern to the
    data can pull the current users ShortDate format and use that for
    formatting. I think that is pretty simple to do in Delphi.

    For future reference, please post questions to new threads. That will help
    us out quite a bit. :)



    --
    Nard Moseley
    Digital Metaphors
    http://www.digital-metaphors.com


    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited April 2004
    In article <40857399$1@dm500.>, support@digital-metaphors.com (Nard
  • edited April 2004

    Okay, maybe we'll both just keep singing the same song. :)

    The formatting in ReportBuilder is completely customizeable. You state you
    have created a TmyDisplayFormat class - so you are well on your way to
    accomplishing your goal. You should be able to implement the following:

    1. Specify what formatting patterns are available to end-users:

    You can override the GetDisplayFormats methods to return whatever format
    patterns you want to make available to the user. You can put '@' signs or
    whatever type of symbols you want.

    2. Formatting data displayed in a report

    You can override the Format method to implement custom formatting logic. The
    Format method is called even when no DisplayFormat is specified for the Text
    component. Thus you can define default DataTime formatting quite easily.

    Here is the default logic for dtDateTime:

    dtDateTime:

    if Length(aDisplayFormat) > 0 then
    Result := FormatDateTime(aDisplayFormat, aValue)
    else
    Result := FormatDateTime('c', aValue);

    If you do not like the time portion being displayed by default, you could do
    something like this (note: this is the default logic for the dtDate case):

    dtDateTime:

    if Length(aDisplayFormat) > 0 then
    Result := FormatDateTime(aDisplayFormat, aValue)
    else
    Result := FormatDateTime(ShortDateFormat, aValue);

    The ShortDateFormat is the Delphi global variable that pulls the format
    pattern from the machines locale.







    --
    Nard Moseley
    Digital Metaphors
    http://www.digital-metaphors.com



    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited April 2004
    In article <408fbcb0$2@dm500.>, support@digital-metaphors.com (Nard
This discussion has been closed.