Please enable JavaScript to view this site.

ASQL Reference

Navigation: » No topics above this level «

DATES

Scroll Prev Top Next More

Reviewed and revised April 2024

xcall DATES, opcode, result, <params...>

DATES performs several different date utility functions and has several calling formats, as shown below.  

Parameters

opcode  (Num)  [in]

specifies operation to perform:

Symbol

Value

Operation

Syntax

DTOP_CVTFMT

1

Convert one format (date1) to another (date2)

xcall DATES, 1, result, date1, date2

DTOP_DATEAFTER

2

Compute date (date2) which is a specified number of days (days) after date1

xcall DATES, 2, result, date1, date2, days

DTOP_DAYSAFTER

3

Compute number of days date1 is after date2

xcall DATES, 3, result, date1, date2, days

DTOP_YWD

4

Compute date2 based on year, week, day of week in X,6 or X,5 format of date1

xcall DATES, 4, result, date1, date2

DTOP_YWMD

5

Compute date2 based on year, month, week and day of week in X,6 format of date1

xcall DATES, 5, result, date1, date2

DTOP_EOM

6

Compute date2 as last day of month in date1

xcall DATES, 6, result, date1, date2

DTOP_ODTIM

7

Output formatted date (similar to ODTIM)

xcall DATES, 7, result, testdate, time, flags, outbuf'or'chan

DTOP_IDTIM

8

Input formatted date (similar to IDTIM)

xcall DATES, 8, result, inputstr, flags, outdate, outtime

DTOP_RANGE

9

Return out'of'range (F) <>0 if testdate is not between lodate and hidate (inclusive)

xcall DATES, 9, result, testdate, lodate, hidate, out'of'range

Definition file: ashell.def

 

result  (Num)  [out]

returns a code indicating if the operation was successful or what kind of error occurred:

Value

Meaning

0

OK

1

Function number out of range (1-9)

2

Error in conversion of input date

3

Invalid format for date

4

Improper number/type of parameters

5

Invalid format for days

6

Error locating file channel (opcode 7)

 

days  (Signed Num)  [out]

for DTOP_DAYSAFTER, returns number of days date2 is after date1

out'of'range  (Num)  [out]

for DTOP_RANGE, returns zero if testdate is within range defined by lodate and hidate (inclusive); else non-zero.

date1, date2, testdate, lodate, hidate

used for input and output, depending on the operation, with the format based on the way they are mapped:

MAP1 ADATE,S,8          ! MM/DD/YY or DD/MM/YY; see note below

MAP1 BDATE,S,10         ! MM/DD/CCYY or DD/MM/CCYY; see note below

MAP1 XDATE              ! Separated format (3 to 7 bytes)

   MAP2 MONTH,B,1

   MAP2 DAY,B,1

   MAP2 YEAR,B,1

   MAP2 DOW,B,1         ! 1=Monday...7=Sunday (optional)

   MAP2 YWEEK,B,1       ! Week of year (1-52)     (optional)

   MAP2 MWEEK,B,1       ! Week of month (1-5)     (optional)

   MAP2 MDAYS,B,1       ! Days in month (1-31)    (optional)

MAP1 IDATE,B,4          ! Internal true Julian

MAP1 BDATE,B,3          ! Std AMOS date (same as 3 byte XDATE

MAP1 CDATE,B,2          ! Century Julian (days since 1/1/1900)

MAP1 JDATE,B,2          ! Yearly Julian (days since start of yr)

MAP1 FDATE,F,6          ! Special case (0=today on input)

 

inputstr (String)  [in]

should be set to the date and/or time to be converted, with the time following the date (with a space separator) if both date and time are included. (Also see flags parameter, which indicates if date and/or time are present.) The date, if present, should be in MM-DD-{CC}YY or DD-MM-{CC}YY format, depending on your language definition file specification for date order. The separator character, however, need not be a dash or even match the language definition file; it can be any non-numeric character. The time format is HH:MM{:SS} {AM/PM}. Legal examples would be:

12/30/07 13:01

01-01-2007 10:15:33 PM

23:01:10

05.03.1915

 

If only two digits are specified for the year, it is assumed to be in the twentieth century (19xx) unless the SBR=CCYY is included in miame.ini, in which case it will determine the YY cutoff below which we assume 20xx instead of 19xx.

outdate (Structure)  [out]

will return the date in system separated format, or zero if the date is not included in the input string. Note that to access the individual fields while still being able to test the overall value for 0, it should be mapped as an overlay per the following:

MAP1 Sepdate

  MAP2 Mon,B,1              ! Month 1-12

  MAP2 Day,B,1              ! Day 1-31

  MAP2 Yr,B,1               ! Year-1900

  MAP2 Dow,B,1              ! Day of week (0=Mon, 6=Sun)

MAP1   Bdate,B,4,@Sepdate    ! B,4 version of Sepdate, as used by

                            !  the DATE system function

MAP1   Idate,F,6             ! F,6 version as needed by IDTIM

 

xcall IDTIM, StringFmt, Idate, Itime, Flags, Status

Bdate = Idate

Print "Separated date: ";Mon;Day;Yr;Dow

Bdate = DATE                 ! Get today's date (for comparison)

Print "Today's separated date: ";Mon;Day;Yr;Dow

 

outtime (Bitmap 4)  [out]

will return the internal format time (i.e. seconds since midnight) or zero if the time is not present.

flags (Num)

should be set to 0 to process both the date and time; 1 if the string is expected to contain only the time, and 2 if it is expected to contain only the date.

Notes

DATES considers a 4 byte binary input date to be in internal Julian format, rather than in the standard AMOS system date format (which is actually a separated date format). A common mistake is to pass DATES a date in B4 format which was returned from the system DATE function or IDTIM, leading to massive confusion, especially when using the range testing operation (9).
The system parameter setting SBR=CCYY:## is used to determine the century cutoff on input dates in MM/DD/YY format. For more details, see the SBR command.
The order of the parts of an eight or ten character string date is based on the LANG'DATE'FORMAT field in the current language definition file, which is month first for the US, day first for most of the rest of the world.  

Counting Weeks

DATES counts the days of each week from Monday=1 to Sunday=7. (That may be a little strange, since most calendars show Sunday as the first day of the week instead of the last. But DATES is a port of some existing AMOS routine, so it was A-Shell's task to preserve the existing behavior, not to justify it.)

The weeks are counted like rows in a calendar, again taking into account that our calendar weeks start with Monday and end with Sunday. So for 2011, the first week had only 2 days: Saturday and Sunday. Jan 3 was the start of the 2nd week.

If you want to convert to a more standard calendar arrangement, where each week starts with Sunday and ends with Saturday, then just add +1 to Mon-Sat and for Sunday, set it back to 1 and add +1 to the week.

On the other hand, if you want to say that each week of the year, including the first one, has seven days, then the week is simply the "yearly Julian" (DATES option 6) divided by seven, truncating the fractional remainder and then addding one (so the first week is one rather than zero). Under that scheme, Mar 15 is the 74th day; 74/7 = 10.57; truncate to 10 and then add 1 to get the 11th week (which it is).

 

History

July 2017, A-Shell 6.4.1551:  Bug fix: Opcode 3 (DTOP_DAYSAFTER) was failing to handle the negative case properly, returning a large positive number instead of a negative number if date1 was before date2. Problem was introduced around 6.3.1516. Same fix as 6.5.1610.

2017 February, A-Shell 6.4.1543:  Bug fix: DATES was outputting mm/dd/yy when it should have been mm/dd/ccyy—i.e. when the output string length >= 10.