TN 012: Creating a Custom Date to use in the Report Name Format

With the latest version of Dream Report (4.6x), this is very simply accomplished:

  1. Open the “General” tab of the Report Settings, and click the “Configure File Timestamp” option to be the “Report Start Period”, and then select “Last 1 Day”:
  2. Then, in the “Report Name Format” tab, either use the default setting (which uses the full date/timestamp), or select and add “Date” only, if the time is not needed in the file name:

Unfortunately, Dream Report 4.5x did not include this feature, so there are several steps you need to follow to create an object containing “yesterday’s date”, and then reference that object in the Report Name Format.

  1. In Dream Report Studio:

    1) Place a “Date and Time” object on the report

    2) Name the object “rptDate”

    3) Set the Option for Dynamic Generation to be “Start of Report period”

    4) Select the Date (and Time, if needed), and set the formatting

    5) For the Time Definition, select “Fixed Period – Last 1 Day”

  2. Since the Date and Time object is returned in Unix time, we have to format it into a local time format. To do this, we use an Expression object, and use a Lua script to format it as needed. In Dream Report Studio:

    1) Place an “Expression” object on the report

    2) Name the object “ReportDate”

    3) In the expression area, enter the following expression exactly as shown:

    (function() return os.date("%m-%d-%Y", [dt#rptDate]) end)()

    You can change the date formatting, as well as adding the time component, as needed. Appendix A describes additional formatting option..

    4) This expression referenced the “rptDate” object we created previously

    5) If you want to hide this object on the report, simply select the “Result Representation” tab, and uncheck the “Visible” option

  3. Now that we’ve created a formatted Date object with yesterday’s date, we can reference it in the Report Name Format. Open the Report Settings, select the “Report Name Format” tab and configure the name as follows:

    1) Delete the [d#FULL_TIMESTAMP] parameter from the “Report filename mask”

    2) In the “Select Data Item” section, click the browse […] button

    3) Select the “Analytics” driver in the “Select Data Source” list. “Analytics” is an internal driver, which exposes all named items/objects on every report.

    4) Double-click your report from the list (in this example, the report name is “Daily Report”, and then select the “ReportDate” object we created in the previous section

    5) Once selected, click the “Add” button in the “Select Data Item” section, to add this item to the Report Filename Mask. The result should look like:

     [s#ReportName]+_+[i#Analytics.Daily Report:ReportDate]


Lua Script Date and Time Manipulation

The following table shows each tag, its meaning, and its value for September 16, 1998 (a Wednesday), at 23:48:10. For numeric values, the table shows also their range of possible values. Reference http://www.lua.org/pil/22.1.html

In a Dream Report Expression object, the syntax to show a “full” date and time, with date elements separated by forward slashes (/) and time components separated by colons (:) would be as follows:

(function() return os.date("%Y-%m-%d %H:%M:%S", [f#exp3]) end)()

Where [f#exp3] is an object which exists on a report.

This would return, for example, the following date and time formatted result: 2013-10-17 09:30:15