Days

From BR Wiki
Revision as of 14:53, 13 January 2012 by Mikhail.zheleznov (talk | contribs) (edit)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

DAYS (date[,format$])

DAYS returns the absolute, sequential value which is assigned to dates after January 1, 1900.

The "C" - century format specification is fully supported. BaseYear is used to determine the century for a date if the format specification used does not specify a century. See "BaseYear" in the BRConfig.sys specifications section for complete information.

Comments and Examples

PRIOR CENTURY

The Days function returns the specified date as a sequential value in relation to a base date of January 1, 1900. As an example of using this parameter for date arithmetic, line 300 would print "PAST DUE" if the date of an invoice (IDATE) is over 30 days from the current date.

00030 IF Days(DATE)>Days(IDATE)+30 THEN PRINT "Past Due"

The DAYS function can now be used to store and perform date arithmetic on dates beginning with year 1700. Negative numbers are used to denote such dates.

Notice that the number of days in a month, leap year, etc. do not have to be coded in your program because they are built into this function.
If the numeric date parameter is invalid, the Days function will return zero. Therefore, the Days function can also be used to check the validity of dates entered from the keyboard. For example,

00010 LET DATE$("*y/m/d") ! be sure default format is year/month/day
00020 LET M$="14"     ! month is invalid
00030 LET D$="31"
00040 LET Y$="88"
00050 LET D=VAL(Y$&M$&D$) ! D = 881431
00060 PRINT Days(D)    ! invalid date = 0
00070 LET M$="12"     ! month is valid
00080 LET D=VAL(Y$&M$&D$) ! D = 881231
00090 PRINT Days(D)    ! valid date = 32507
00095 LET DATE$("*m/d/y") ! change default format to month/day/year
00096 PRINT Days(D)   ! invalid date = 0 (does not fit format)

The value of D in line 96 is invalid because line 95 changes the default format for dates (note the * at the start of the date string). The optional second parameter of the Days function can be used to temporarily change the date format. Line 97 will print a nonzero value because the date is valid in the format specified in the optional string parameter.

00097 PRINT Days(D,"y/m/d") ! valid date = 32507
00098 PRINT Days(D) ! invalid date = 0 (does not fit format specified  in line 95)

Line 98 returns zero because the format in line 97 only applies to that one function call. Since there is no asterisk in the date string, line 97 does not change the default date format, whereas line 95 does.

Parameters

The "date" parameter is a numeric expression that represents the date for which the number of days should be calculated. If "date" is not valid according to the current default format, Days will return 0.

The optional "format$" parameter is a string expression which identifies the format of the value to be returned. When the first character of the string expression includes an asterisk (*), it identifies the default format which should be used by the Date, Date$ and Days parameters until the workstation exits Business Rules or until the format is changed again. (Format changes affect the current workstation only.)

The format$ parameter may include editing characters and any of the following date specifications: D (day), M (month), Y (year) or C (century). The total number of editing characters and date specifications may not exceed 6. Consecutive repetitions (DDD, YY, etc.) of the date specifications count as just one specification, but consecutive repetitions of editing characters do not use this rule. See the Date$ function for additional information about format$.

Related Functions

See also Date$ and Date for other date processing functions.