Home page  
Help >
Date Functions
Version 7.11
Date Functions Date Functions

There are four CALC date functions and one SET date function. The CALC date functions always result in a numeric that is a julian date, and the SET date function results in a string that is the calendar date in MM/DD/YYYY form, or in the form specified by the template given with the command.

The basis for julian dates is Jan 1, 1001. The range of our internal calendar is from 1/1/1001 to 12/31/9999. For more information about our calendar see the description of the CALENDAR command.

The CALC Date Functions

JDATE:

calc %jd=jdate(date[;"template"]) Convert calendar date to julian date

The input date is a calendar date and can be a fieldname, a variable, a literal, or the value 0. Zero means today's date. The template is optional in the command, but if supplied, it must be surrounded with quotes. If the input date is in MM/DD/YYYY form, there is no need to supply the template since that is the default assumption. The result is always the equivalent julian date for the supplied calendar date. Some examples:

calc %today=jdate(0)
The result is the julian value for today's date.

calc %dt=jdate(%xx;"YYYYMMDD")
The result is the julian value for the calendar date contained in
the variable %xx. The form of the date in %xx was YYYYMMDD.

calc %elapsed=jdate(%ending) - jdate(%beginning)
The result is the number of days between an ending date and a
beginning date, both of which were in MM/DD/YYYY form in their
respective variables.

Testing for Bad Input Dates (%answer3=1 from JDATE)

The JDATE function makes use of %answer3 to report a bad input date. A bad date would be one where the day, month, or year was not valid in the input date string supplied to JDATE. If %answer3=1, the input string is invalid. So a handy way to check any date string is to JDATE it and look for
%answer3=1.



The Date Increment Functions

These are functions that increment (or decrement) the day, month, or year based upon a starting date, the increment, and a flag.

calc %result=yrinc(%basis;increment;flag) -increments years
calc %result=moinc(%basis;increment;flag) -increments months
calc %result=dyinc(%basis;increment) -increments days

where:
%result
is always a julian date
%basisis always a julian date
incrementis (+ or -) a whole number
flagis a number between 1 and 31 inclusive
if flag=31, always gives back the last day of a month
if flag ne 31, always gives back that day if it can

These are for "same date next year" or "same date next month" and you do not have to worry about if it was a leap year (or not) in the first case, or if it was a 28, 29, 30, or 31 day month in the second case.

For example, suppose %xxx was Jan 17, 1998 and you want to add 3 months to it and get April 17, 1998. Suppose further that the form of %xxx was
MM/DD/YYYY, or in this case, 01/17/1998.

calc %m=jdate(%xxx)
set %day=edate(%m;"dd") -this gets the value for the 3rd arg
calc %newdt=moinc(%m;3;%day)

Now if we take the EDATE of the result:

set %result=edate(%newdt) -we get 04/17/1998




The EDATE Function:
Converting Julian dates back into Calendar dates

This is the SET function because the result is always a string that is the calendar date in the form MM/DD/YYYY or in the form of the template sup-
plied with the command.
TEMPLATE CHARACTER DEFINITIONS
L - Last day of month
M - Numeric month
set %v=edate(date[;"template"]) X - Alpha month
D - Numeric day
Z - Alpha day
Y - Year

The input date is a julian date and can be a fieldname, a variable, a literal, or the value 0. Zero means today's date. The template is optional in the com-
mand, but if supplied, must be surrounded with quotes. There is no need to supply the template if the desired result is to be MM/DD/YYYY form. Some examples:

set %dt=edate(0) -gets today's date in MM/DD/YYYY form

Suppose %aa contains the value 364757:

set %dt=edate(%aa) -%dt becomes 09/02/1998
set %dt=edate(%aa;"xxx dd, yyyy") -%dt becomes Sep 02, 1998
set %dt=edate(%aa;"yyyymmdd") -%dt becomes 19980902
set %dt=edate(%aa;"mm-dd-yyyy") -%dt becomes 09-02-1998
set %dt=edate(%aa;"mm/LL/yyyy") -%dt is 09/30/1998 (Last day)
set %dt=edate(%aa;"zzz xxx dd") -%dt becomes Wed Sep 02
set %dt=edate(%aa;"zzzzzzzzz") -%dt becomes Wednesday
set %dt=edate(%aa;"xxxxxxxxx") -%dt becomes September
set %dt=edate(%aa;"dd") -%dt becomes 02
set/m %dt=edate(%aa;"zzzzzzzzz xxxxxxxxx dd, yyyy")
Now %dt becomes Wednesday September 02, 1988. The M
option on the SET command was employed to remove
excess blanks so as to cover cases where the day or the
month does not contain 9 letters.

Copyright © 2019 , WhamTech, Inc.  All rights reserved. This document is provided for information purposes only and the contents hereof are subject to change without notice. Names may be trademarks of their respective owners.