 

Abstract: Statit
provides a family of functions for performing
date computations. One of the most powerful
of these is the setintrvl()
function. The setintrvl()
function returns a Statit date or time value
that is a specified number of intervals from
a particular date or time. We illustrate this
function for the problem of finding the date
for Friday last (or today if today is Friday).
Products:
Statit
e-QC, Statit
e-Server, Statit
Custom QC
Date computations are always a bit tricky with
the Gregorian calendar. This is why Statit uses
Julian dates for all date values and computations.
A Julian date in Statit is simply the number
of days since December 31, 1899. For example,
in Statit a Julian date of 1 is January 1, 1900,
and a Julian date of 36525 is January 1, 2000.
Dates prior to December 31, 1899 are simply
negative values. For example, July 4, 1776 is
45104. The value date range for Statit
is from January 1, 1753 to December 31, 2199.
Statit provides a family of functions for performing
date computations. One of the most powerful
of these is the setintrvl()
function. The setintrvl()
function returns a Statit date or time value
that is a specified number of intervals from
a particular date or time. For example, setintrvl(3,'10-apr-2000',0)
will return a date value of April 1, 2000, which
is the beginning of the month. The first parameter,
3, specifies that the interval will be in months
and the third parameter, 0, is the number of
intervals. When the number of intervals is 0,
the beginning of the interval is returned.
Weeks are another possible interval; e.g.,
setintrvl(2,'10-apr-2000',3)
will return the date that is forward 3 weeks,
May 01, 2000. The first parameter, 2, specifies
that the interval will be in weeks.
Now back to the problem of determining the
date for Friday. This can be done with a single
command:
let
friday = (day(2) >= 6) * (setintrvl(2,day(4),0)+5)
+ ;
(day(2)
< 6) * (setintrvl(2,day(4),0)-2)
This command uses the day()
and setintrvl()
functions. The day()
function with a parameter of 2 returns the current
day of the week, where 1=Sunday and 7=Saturday.
The day()
function with a parameter of 4 returns todays
date.
The relational expression, day(2)
>= 6, will result in a value of 1
if today is Friday or Saturday and 0 otherwise.
Similarly, day(2)
< 6, will result in a value of 1 if
today is from Sunday to Thursday and 0 otherwise.
We can use the result of this relational expression
as a multiplier to apply logic to another part
of the computational expression.
The next part of the expression, setintrvl(2,day(4),0),
returns the first day of the current week, which
is Sunday. If the current day is Friday or Saturday,
then we will add 5 days to this Sunday which
will be Friday. Otherwise, we will subtract
2 days from Sunday which will be the previous
Friday.
The resulting date will be stored with its
Statit Julian value in the variable Friday.
A print format can be assigned to display the
value with a date format:
printformat
friday lo to hi = "%11j"
There you have it. This illustrates how Statits
date functions can be used to solve a complex
date computation. For more information, refer
to the online documentation for these functions.
Also see Statit
Date and Time Overview
If you would like additional information, please
call our Support staff at (541) 752-4100 or
send email to
.
|