DATE FORMATS
1. Date Input Formats
2. Date Output Formats
3. DATE( Function
4. DAYS( Function
5. MONTHS( Function
DATE INPUT FORMATS:
These are the valid formats for date strings used with the DATE(, DAYS(, and MONTHS( functions:
FORMAT EXAMPLE (09/17/91): mmddyy 091791 ddmmyy 170991 yymmdd 910917 mmddyyyy 09171991 ddmmyyyy 17091991 yyyymmdd 19910917
Optionally, use a hyphen, slash or space to separate elements of the date input string (e.g., 07-04-91, 12/25/91, 03 11 91). If a date string entered for the DATE() function is ambiguous (e.g., the string "110391" could be March 11 or November 3), Shark reads the string according to the format set by the SET DATE command.
Date INPUTS are prone to errors, so it's better to firmly format all date inputs using @...SAY...GET...READ constructs.
DATE OUTPUT FORMATS:
These are the 10 output format numbers for use with the DATE() function.
Number Name Display 0 day of week, month name, day, year (reset entire saystem to today's date) \ 1 YMD yymmdd (6 characters: 990601) 2 MDY mm/dd/yy (8 characters: 06/01/99) 3 CHAR Month name, day, year (variable length: June 1, 1999) 4 FULL day of week, month name, day, year (variable length: Sunday, June 1, 1999)(local application/work-station only) 5 Lchar Last day of month (variable length: June 30, 1999) 6 DMY dd-mmm-yyyy (11 characters: 01-JUN-1999) 7 VARIABLE Format determined by the SET DATE command (variable length) 8 LONG yyyymmdd (International ISO-8601 standard date) 9 LAST yymmdd or yyyymmdd, depending on format specified with SET DATE
Date information can be further enhanced by using the PICTURE format.
Example:
1>? date(8) ; i.e. LONG ISO-8601 date format 20031205 1>? date(8) pic("XXXX.XX.XX) 2003.12.05
DATE( Function:
Displays a date in a specific format, or update :DATE with the computer's system date.
DATE(type[,str exp]
type = one of 10 type basic date-output formats, e.g. "8"
Option: str exp = the date to be converted, e.g. "08-23-19"
Type: character
This function has three distinctly different purposes and results:
1. with only type specified in the range 0-9, rewrites the current Shark date in :DATE in the format specified by the type, and returns the result.
2. with two parameters (the format in the range 0-9, and the date) returns the given date in the specified format. :DATE is not effected.
3. with only type specified as zero, updates the Shark date with the computer's current system date, and the computer time with the current system time. The Shark and system dates are always the same when Shark is started, but the Shark does not automatically advance at midnight as the computer's system date should. When Shark can be in use overnight, or even for days at a time, it may be important to ensure that these dates are kept in synchronization. Returns a string of length zero.
The type can be given in either of two forms, a name or number (numeric expression) as follows:
Type Date-output format ------------- ----------------------------------------------------------- 0 system-wide date reset 1 or YMD 6-character format without slashes: yymmdd 2 or MDY 8-character format with slashes: mm/dd/yy 3 or Char Spelled out: Month dd, yyyy 4 or Full Spelled out: Weekday, Month dd, yyyy; similar to date(0), but local workstation only 5 or Lchar Last day of month spelled out in format 3 (Char) 6 or DMY 11-byte string in format dd-MMM-yyyy (example 03-NOV-1990) 7 or Variable formatted without slashes according to SET DATE TO command (See SET DATE TO) 8 or Long ISO-8601 standard 8-character format without slashes: yyyymmdd 9 or Last Last day of month in format 1 (YMD) or 8 (Long), depending on whether SET DATE TO command set year to YY or YYYY
Shortcut: When specifying type by name, only the first character is usually required. The exception is for Lchar, Long, and Last, which require two characters to resolve ambiguity. If only one is given, Lchar is assumed.
Note: No name equivalent is provided for type 0, which updates the Shark date from the computer's calendar setting.
str exp must contain the date in one of the following formats:
mmddyy ddmmyy yymmdd mmddyyyy ddmmyyyy yyyymmdd
Optionally, a slash, a hyphen, or a space may be used to separate the elements of these formats. For example, YY/MM/DD, YY-MM-DD, YYYY MM DD are all equally valid.
There should be two digits each for month and the day, and two or four digits for the year. 01 3 92 is not acceptable. If str exp is not acceptable, then DATE( returns a string of blanks.
In the event of ambiguity, dates will be decoded in accordance with the format set in the SET DATE TO command. For example:
SET DATE TO date is interpreted as ------------- ------------- ------------------ 'ddmyy' 11/03/99 March 11, 1999 'mmddyy' 11/03/21 November 3, 2021 'mmddyy' 11/03/60 November 3, 2060
See also the system variable :DATE and the command SET DATE TO.
Examples:
1>:DATE= '10/05/99' 1>? :DATE 10/05/99 1>? DATE() 19991005 1>? :DATE 19991005 1>? DATE(1) 991005 1>? :DATE 991005 1>? DATE(2) 10/05/99 1>? :DATE 10/05/99 1>? DATE(3) October 5, 1990 1>? :DATE October 5, 1990 1>? DATE(4) Saturday, October 5, 1990 1>? :DATE Saturday, October 5, 1990 1>? DATE(4,'12/08/90') Sunday, December 8, 1990 1>? :DATE Saturday, October 5, 1990 1>? DATE(5,'90-30-27') March 31, 1990 1>? DATE(6,'03 27 90') 27-Mar-1990 1>1>? date(8,'03-18-10') 2010-Mar-18 <-- ISO-8601 standard sequence 1>? :DATE Saturday, October 5, 1990
If the time has passed midnight during the current run of Shark, you can update the Shark date with DATE(0):
1>? DATE(0) 1>? DATE(4) Sunday, October 6, 1990
A preferred date format such as ISO-8601 standard can be stored in Shark's .CNF file as a system variable. It's then visible to all applications in Shark:
:UNDOC=PIC(DATE(8),"XXXX.XX.XX")
Calling :UNDOC will show today's formatted date, properly sequenced according to the ISO-8601 standard. This is useful for screen displays, menus, etc. For date-dependent data such as transactions, invoices, etc, use the unformatted date(8). This is the most useful format for aging data since your data file can be directly indexed by date.
Computes dates and date differences in days.
DAYS(<str exp1>,<str exp2>) DAYS(<str exp>,<num exp>)
NOTE: In the first form, str exp1 and str exp2 are dates. In the second form, str exp is a date and num exp is a number
Type: numeric/character
In the first form, DAYS( returns the number of days between two dates. The result is an integer.
In the second form, DAYS( returns the date (as a string) which is num exp days past or before the date str exp.
The string expressions containing dates can be of many different formats (see the DATE( function for more examples):
yy/mm/dd yy-mm-dd yyyy mm dd mm/dd/yy mm-dd-yy mm dd yy
There should be two digits each for yy, mm, and dd, and four digits for yyyy. 01 3 90 is not acceptable.
In the second form, the date is returned in the format set with the SET DATE TO command (default: mmddyyyy). If you wish a different format, use the DATE( function. See also MONTHS( and SET DATE TO.
Examples:
1>? DAYS('04 06 90','04 29 90') 23.00 1>? DAYS('01/01/88','01 23 90') 753.00 1>? DAYS('01/01/90','01 23 88') -708.00 1>? DAYS('01/01/91','01 02 91') 1.00 1>? DAYS('01/02/91','01 01 91') -1.00 1>? DAYS('02/28/88','03 01 88') ;leap year 2.00 1>? DAYS('02/28/90','03 01 90') ;not a leap year 1.00 1>? DAYS('04 03 90',30) 050290 1>? DAYS('02 03 90',30) 030590 1>? DAYS('02 03 90',-3) 010490 1>? DAYS('020390',-30) 010490 1>monthday='0203' 1>offset=30 1>? DAYS(monthday+'90',offset+1) 030690
DAYS( and DATE( may be combined to form complex expressions. For instance, the end of the month closest to today in the form set in the SET DATE TO command:
DATE(7,DAYS(DATE(2),-15))
The end of NEXT month:
DATE(5,DAYS(DATE(2),30))
See DATE( and MONTHS( functions, and SET DATE TO command.
Computes date differences in months.
MONTHS(/num exp) <date1> a string expression containing a valid date
Options:
<date2> a string expression containing a valid date; when <date2> is specified, MONTHS( returns number of months between the two dates num exp number of months before or after date1; when specified, MONTHS( returns date that many months away Type: character/numeric
MONTHS( computes the difference between the two dates in months, or computes a date a given number of months before or after a specified date. Fractional parts of months are discarded.
If a computed date is after the last date of the month, the date will be adjusted to the last day of the month. For example, MONTHS('013190',1) results in 022890.
Examples:
1>? MONTHS('04 06 90','04 29 90') 0.00 1>? MONTHS('01/01/90','02/01/90') 1.00 1>? MONTHS('02/01/90','01/01/90') -1.00 1>? MONTHS('01/01/90','01/01/92') 24.00 1>? MONTHS('02/01/90',10) 120190 1>? MONTHS('01/01/90',-6) 070189