The
Dating Files
By Steve Hammond
Inside VESOFT covers
tips and techniques you can use with VESOFT’s products,
especially MPEX.
By Steve Hammond
Synchronicity
is defined by Webster’s as the coincidence of events that seem
to be meaningfully related, conceived in Jungian theory as an
explanatory principle on the same order as causality. (I’m okay
up until the comma, but when we get into “Jungian theory” I
kinda glaze over.)
I can’t tell you
how many times I have completed an Inside Vesoft column and within
days found myself using the exact command or procedure I discussed in
the column. It happened just last month when I needed to alter
several spool files and used the ALTSPOOLFILE command.
This was slightly
different, because I needed to select by a range of dates. I had to
dig into the back of the manual to the Appendix to look over some of
the date functions. There I realized the vast number of date
operators and functions offered in MPEX and its companions. No one
really worried about dates until less than 10 years ago when the turn
of the millennium was looming, but we’ve always been able to do
any number of functions with dates in MPEX.
We all know that
TODAY is a date function  I regularly run:
%YESPURGE
LOG####.PUB.SYS(accdate<TODAY60) to clear all the log files older
than 60 days off my system. But you can do a lot more when it comes
to calculating and comparing dates. (You can test these commands
using the CALC command, so you can check it before deleting an entire
account.)
%calc today1
04/04/20
Now that date looks
funny. That’s because the date returned is in the YYMMDD format.
If I tell it I want to create the date (CDATE) in a month/date/year
format, I need to:
%calc cdatemdy(04/19/041)
04/18/04
Of course, you can do
addition and even differences between dates:
%calc 06/25/0402/29/04
117, $75,
%165, "...u"
Here we see that the
difference between June 25th and February 29th of this year is 117
days. Wait a minute  that output is not what we expected! Using
CALC, if the result is an integer, it will be displayed in decimal,
hexadecimal, octal and ASCII representation of the 4 bytes with
periods replacing the junk/unprintable characters.
And what’s data
manipulation if you can’t do boolean?
%calc (04/20/04=03/20/04)
FALSE
or
%calc
(04/20/04<>03/20/04)
TRUE
Of course you can do
the standard greater than, less than, equal to, less than or equal
and greater than or equal.
You can even
do MIN, MAX and BETWEEN functions on dates:
%calc MIN
(04/21/04,03/22/04,09/22/01)
09/22/01
%calc MAX
(04/21/04,03/22/04,09/22/01)
04/21/04
%calc BETWEEN
(04/21/04,03/22/04,09/22/01)
FALSE
As you can see BETWEEN is
a boolean function, determining if the first date is between the
second and the third  and as you can see in this instance, it is
not.
If you need to extract
certain segments of a date, there are functions  DATEYEAR gives you
the twodigit year from a date, DATEYEAR4 extracts the fourdigit
year, DATEMONTH AND DATEDAY provide the obvious and DATEDAYOFWEEK
gives the day of the week:
%calc DATEYEAR(04/21/04)
4, $4, %4,
"...."
%calc
DATEYEAR4(04/21/04)
2004, $7D4,
%3724, "...."
%calc
DATEMONTH (05/26/01)
5, $5, %5,
"...."
%calc
DATEDAY(05/26/01)
26, $1A, %32,
"...."
%calc
DATEDAYOFWEEK(05/26/01)
7, $7, %7,
“....”
In the last case, May
26, 2001 fell on a Saturday (1 is Sunday, 2 is Monday, etc.)
In my last
job, where Julian date was used regularly, this came in handy
%calc DAYOFYEAR(04/21/04)
112, $70,
%160, "...p"
Julian date, as
defined in most applications, is the number of the day in the year 
January 1st is 1, December 31st is 365 or 366 this year. As an aside,
in my limited Unix experience, I was struck that it was odd the
definition of a Julian date on that system was the number of seconds
since some seemingly arbitrary, but no doubt significant date in the
past — oh well.
The function CDATE is
really expanded into three other simpler commands, all involving
conversion of dates:
%calc CDATEMDY (87/01/15)
01/15/87
%calc
CDATEYMD (04/26/99)
99/04/26
%calc
CDATEDMY (04/15/02)
15/04/02
So you can
easily convert one date format to another.
It’s not
uncommon to need to determine if a date is valid:
%calc
VALIDDATE("06/25/2003","MDY")
TRUE
%calc
VALIDDATE("02292004","MDY")
TRUE
%calc
VALIDDATE("022903","MDY")
FALSE
As you can see, it works
with or without slashes, on two or fourdigit years and it
recognizes valid leap year days. The quotes in there are important
— I learned the hard way — had a job blow up at an
inopportune time because I forgot the quotes.
So, MPEX lets you
deal with dates better than my college roommate, but that’s a
story for another day.
The only Jung
that Steve Hammond, who works for a professional association in
Washington, DC, knows is a middle relief pitcher for the Philadelphia
Phillies!
Copyright The 3000 NewsWire. All
rights reserved.
