FieldIsNull does not work for dates

My objective in a report was that if a date field is null, print a blank (or <<< NULL >>> for debugging purposes) otherwise the date and time.

In my version which is the latest there is 'FastReport 2.51 Undocumented features', which mentions the FieldIsNull function for scripts.

My problem is that with dates it does not work. The logic

if FIELDISNULL([dmManagement.cdsResults."TransferredWhen"]) then
DateTransferred := '<<< Null >>>'
else
DateTransferred := FormatDateTime('dd/mm/yyyy hh:mm:ss',[dmManagement.cdsResults."TransferredWhen"]);

Returns with every date being NULL.

My work around is to use this logic

DateTransferred := FormatDateTime('dd/mm/yyyy hh:mm:ss',[dmManagement.cdsResults."TransferredWhen"]);
if DateTransferred = '30/12/1899 00:00:00' then DateTransferred := '<< NULL >>'

The other interesting thing is that I use the text memo editor to insert a date field, I get a value of zero displayed rather than the usual null date value of
30/12/1899 00:00:00.

If I use the designer to add a date field to a band it works ok.

I am using ADO via clientdatasets if that is causing any upsets. ;)

Comments

  • edited 5:42PM
    Use the [(FIELDISNULL( ' [dmManagement.cdsResults."TransferredWhen"] ' ))] syntax. Note the surrounding apostrophes around the fieldname.

    Regards:Alex
  • edited 5:42PM
    Sorry I should have looked more closely at your documentation.
    However I added the extra quotes but it still does not work. Everthing is still
    reported as a null. Using two different date fields, I have reported each field three times in the same report, as it comes from the database, using the FieldIsNull function and
    using the formatdatetime function and checking for 30/12/1899.

    The FieldIsNull always reports it as null.

    I can send you a prepared report if you like and the frf file. ;)
  • edited 5:42PM
    Just to make sure I was not making more syntactic mistakes I tried

    (which matches thwe documentation)

    if FIELDISNULL('[dmManagement.cdsResults."TransferredWhen"]') then
    Date1A := '<<< Null >>>'
    else
    Date1A := FormatDateTime('dd/mm/yyyy hh:mm:ss',[dmManagement.cdsResults."TransferredWhen"]);

    if (FIELDISNULL('[dmManagement.cdsResults."TransferredWhen"]')) then
    Date1A := '<<< Null >>>'
    else
    Date1A := FormatDateTime('dd/mm/yyyy hh:mm:ss',[dmManagement.cdsResults."TransferredWhen"]);

    and which matches your example in this post

    if [(FIELDISNULL('[dmManagement.cdsResults."TransferredWhen"]'))] then
    Date1A := '<<< Null >>>'
    else
    Date1A := FormatDateTime('dd/mm/yyyy hh:mm:ss',[dmManagement.cdsResults."TransferredWhen"]);

    However I only get null every time. ;)
  • gordkgordk St.Catherines On. Canada.
    edited 5:42PM
    Hi
    try this syntax sub your own values as needed.
    if [(FIELDISNULL('CustomerData.Customers."LastInvoiceDate"'))] then
    code to set what you want...... ;

    works fine for me in bde,ads.
    regards ;)
  • edited 5:42PM
    ;) That worked fine. Thanks a lot. I just had a closer look at the documentation and I see where I went wrong ;) .

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.