Difference between revisions of "Setting the Logical Date"

From Vital Soft Wiki
Jump to: navigation, search
>Johno
(Created page with "=== Current System Date === Most of the common date calculations performed by AskPlus use the current system date as the reference date. For instance, %DAYS-OLD(d1) returns t...")
 
 
Line 5: Line 5:
 
With AskPlus version E.8.2.1 and higher it is possible to set a global reference date (ASK_REFDATE) that will override the system date returned by $SECONDS, which is the AskPlus variable that returns the current date and time in internal format.  When ASK_REFDATE is set, $SECONDS will return a value that corresponds to the specified date and the current time.  Setting this reference date allows you to run a report and have it's date calculations behave as though it had been run on the specified logical date.  (Keep in mind that the data will not necessarily be the same as it was on the reference date.)
 
With AskPlus version E.8.2.1 and higher it is possible to set a global reference date (ASK_REFDATE) that will override the system date returned by $SECONDS, which is the AskPlus variable that returns the current date and time in internal format.  When ASK_REFDATE is set, $SECONDS will return a value that corresponds to the specified date and the current time.  Setting this reference date allows you to run a report and have it's date calculations behave as though it had been run on the specified logical date.  (Keep in mind that the data will not necessarily be the same as it was on the reference date.)
 
* ASK_REFDATE effects the system variables $SECONDS, $TODAY, $YESTERDAY. All other date system variables are based on the actual date.
 
* ASK_REFDATE effects the system variables $SECONDS, $TODAY, $YESTERDAY. All other date system variables are based on the actual date.
 +
* Since many date macros (%CYMD-TODAY, %CYMD-YESTERDAY, %FDAY-PRI-MO, etc) use $SECONDS to perform the date calculation, these macros are all impacted by ASK_REFDATE.
 
* ASK_REFDATE will only be used if it contains a valid date.  If the value is zero, or some other invalid date, it will be ignored and the current date will be used.
 
* ASK_REFDATE will only be used if it contains a valid date.  If the value is zero, or some other invalid date, it will be ignored and the current date will be used.
 +
 +
=== How to set ASK_REFDATE ===
 +
The AskPlus logical date can be set in two ways:
 +
* In a UNIX script by setting a system variable called ASK_REFDATE
 +
* In Visimage3 (or AskPlus code) by creating a '''Global''' variable called ASK_REFDATE
 +
 +
=== Using the Macro DFLT-HR-OFFSET ===
 +
This macro is used by many date macros to calculate the current date. It is designed to create a time window (after midnight) for jobs that may run after midnight, to use the previous day for today. For example, when DFLT-HR-OFFSET is set to 6 hours, jobs that run between midnight and 6:00 am will use the previous day as today's date. Provided you use the macro definition shown below, DFLT-HR-OFFSET will be ignored when ASK_REFDATE is set.
 +
 +
  macro DFLT-HR-OFFSET = !IIF((6 * 3600) splice "|" splice 0, &
 +
                        (!datext($SECONDS, "cymd") = (($YEAR * 10000) + ($MONTH * 100) + $MONTHDAY)))
 +
 +
The DFLT-HR-OFFSET is actually set to a number of seconds. The above is setting the offset to 6 hours (6 * 3600) because there are 3600 seconds in an hour.

Latest revision as of 19:30, 19 January 2023

Current System Date

Most of the common date calculations performed by AskPlus use the current system date as the reference date. For instance, %DAYS-OLD(d1) returns the number of days between any specified date (d1) and the current system date. Many times, however, reports require date calculations based on a different date, ie the end of the previous month, or yesterday's date.

Setting a Logical Date

With AskPlus version E.8.2.1 and higher it is possible to set a global reference date (ASK_REFDATE) that will override the system date returned by $SECONDS, which is the AskPlus variable that returns the current date and time in internal format. When ASK_REFDATE is set, $SECONDS will return a value that corresponds to the specified date and the current time. Setting this reference date allows you to run a report and have it's date calculations behave as though it had been run on the specified logical date. (Keep in mind that the data will not necessarily be the same as it was on the reference date.)

  • ASK_REFDATE effects the system variables $SECONDS, $TODAY, $YESTERDAY. All other date system variables are based on the actual date.
  • Since many date macros (%CYMD-TODAY, %CYMD-YESTERDAY, %FDAY-PRI-MO, etc) use $SECONDS to perform the date calculation, these macros are all impacted by ASK_REFDATE.
  • ASK_REFDATE will only be used if it contains a valid date. If the value is zero, or some other invalid date, it will be ignored and the current date will be used.

How to set ASK_REFDATE

The AskPlus logical date can be set in two ways:

  • In a UNIX script by setting a system variable called ASK_REFDATE
  • In Visimage3 (or AskPlus code) by creating a Global variable called ASK_REFDATE

Using the Macro DFLT-HR-OFFSET

This macro is used by many date macros to calculate the current date. It is designed to create a time window (after midnight) for jobs that may run after midnight, to use the previous day for today. For example, when DFLT-HR-OFFSET is set to 6 hours, jobs that run between midnight and 6:00 am will use the previous day as today's date. Provided you use the macro definition shown below, DFLT-HR-OFFSET will be ignored when ASK_REFDATE is set.

 macro DFLT-HR-OFFSET = !IIF((6 * 3600) splice "|" splice 0, &
                        (!datext($SECONDS, "cymd") = (($YEAR * 10000) + ($MONTH * 100) + $MONTHDAY)))

The DFLT-HR-OFFSET is actually set to a number of seconds. The above is setting the offset to 6 hours (6 * 3600) because there are 3600 seconds in an hour.