Absolute day numbers: Difference between revisions

From Color 64 BBS Wiki
Created page with "Programming Features - <strong>Absolute Day Numbers (ADN)</strong> The BBS system keeps track of the current date in the numeric variable DA as a value called an Absolute Day Number (ADN). An ADN is the number of days that have passed since January 1, 1800 (01/01/1800). This may seem inconvenient at first, but the Color 64 ML routines take care of all the necessary calculations, and you really don't even have to know that this is going on. Yo..."
 
No edit summary
Tag: Manual revert
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[programming features|Programming Features]] - <strong>Absolute Day Numbers (ADN)</strong>
[[programming features|Programming Features]] - <strong>Absolute Day Numbers (ADN)</strong>


The BBS system keeps track of the current date in the numeric variable DA as a value called an Absolute Day Number (ADN).  An ADN is the number of days that have passed since January 1, 1800 (01/01/1800).  This may seem inconvenient at first, but the Color 64 ML routines take care of all the necessary calculations, and you really don't even have to know that this is going on.  You will never see an ADN when your BBS system is online, but you should know about this if you plan to program on your BBS system.  ML functions @15 to @19 are all used to facilitate ADN calculations and conversions.  For more information on what these functions do, consult section 5.1.8, "ML Function Summary".
== Absolute Day Numbers (ADN) ==


The "current time" routine at line 1110 of an overlay is also used to calculate the current date when midnight has come.  All it does is increase the variable DA by one and then use DA to get the value of DA$ and other information as well.  The variable DA$ will hold the current date in the format "MM/DD/YYYY" where MM is the month (00 to 12), DD is the day (00 to 31), and YYYY is the year (1800 to 9999).  The variable D1 will be the current month (1 to 12).  The variable D2 will be the day of the week in the range 0 to 6 for Sunday to Saturday, respectively.  The variable D3 will be the day of the month (0 to 31).  The variable D4 will be the year (1800 to 9999).  
The BBS system stores the current date in the numeric variable <strong>DA</strong> using a format known as an <em>Absolute Day Number</em> (ADN).


The string array variables D1$ and D2$ can be used to convert a date into plain English format.  The strings D1$(1) to D1$(12) hold the names of the twelve months of the year January to December. The strings D2$(0) to D2$(6) hold the names of the days of the week from Sunday to Saturday.  
An ADN represents the total number of days that have elapsed since <strong>January 1, 1800 (01/01/1800)</strong>. While this representation may seem unusual at first, it greatly simplifies date calculations. The Color 64 machine language routines perform all required conversions automatically, so most programs never need to manipulate the ADN value directly.


Other variables which are stored in ADN format are ED (caller's membership expiration date), LD (callers's last call date), and BD (caller's date of birth). Also, when the user's information is read in from their password record, the variables ED$, LD$, and BD$ will be set accordingly.  
Under normal BBS operation, users never see ADN values. However, sysops who write programs or modules should understand how this system works.


To find the difference in days between two dates, all you need to do is subtract the lower ADN from the higher ADN.  This will be the exact number of days between the two dates. Also, to find out what the the current date would be after a certain number of days all you would need to do is add the number of days to the variable DA and you would have the new date.  
Machine language functions <strong>@15 through @19</strong> are used internally to perform ADN calculations and conversions. For detailed information about these functions, refer to the section <em>"ML Function Summary"</em>.


There is also another function, @27, which can be used to find the number of calendar years between two dates. Using this function, you can quickly find the age of someone using the caller's date of birth, by using the format @27(DA,BD).  
 
=== Date Handling in the Time Routine ===
 
The <em>current time</em> routine located at line <strong>1110</strong> of each overlay also manages the system date. When midnight occurs, this routine increments the variable <strong>DA</strong> by one day. The updated value of DA is then used to calculate the other date-related variables.
 
The following variables are derived from DA:
 
{| class="wikitable"
|-
! Variable
! Description
|-
| <strong>DA$</strong>
| Current date in the format <code>MM/DD/YYYY</code>
|-
| <strong>D1</strong>
| Current month (1–12)
|-
| <strong>D2</strong>
| Day of week (0–6, where 0 = Sunday and 6 = Saturday)
|-
| <strong>D3</strong>
| Day of the month (1–31)
|-
| <strong>D4</strong>
| Current year (1800–9999)
|}
 
The formatted date string <strong>DA$</strong> is generated automatically from the ADN value.
 
 
=== Month and Day Name Arrays ===
 
Two string arrays are provided for converting dates into readable text:
 
{| class="wikitable"
|-
! Array
! Contents
|-
| <strong>D1$()</strong>
| Month names, where <code>D1$(1)</code> through <code>D1$(12)</code> correspond to January through December
|-
| <strong>D2$()</strong>
| Day names, where <code>D2$(0)</code> through <code>D2$(6)</code> correspond to Sunday through Saturday
|}
 
These arrays allow programs to display dates in plain English format.
 
 
=== Other ADN-Based Variables ===
 
Several additional variables store dates internally using ADN format:
 
{| class="wikitable"
|-
! Variable
! Description
|-
| <strong>ED</strong>
| Caller's membership expiration date
|-
| <strong>LD</strong>
| Caller's last call date
|-
| <strong>BD</strong>
| Caller's date of birth
|}
 
When user information is read from the password file, the corresponding formatted string variables are also generated automatically:
 
* <strong>ED$</strong> – Membership expiration date (formatted)
* <strong>LD$</strong> – Last call date (formatted)
* <strong>BD$</strong> – Date of birth (formatted)
 
 
=== Calculating Differences Between Dates ===
 
Because dates are stored as Absolute Day Numbers, calculating the number of days between two dates is simple.
 
To determine the number of days between two dates:
 
<code>difference = higher ADN − lower ADN</code>
 
The result is the exact number of days between the two dates.
 
 
=== Calculating Future Dates ===
 
To determine the date after a specific number of days, simply add the desired number of days to the current ADN value:
 
<code>future_date = DA + number_of_days</code>
 
The resulting ADN can then be converted back into formatted date variables using the standard system routines.
 
 
=== Calculating Age or Year Differences ===
 
Machine language function <strong>@27</strong> calculates the number of calendar years between two ADN values.
 
This function is commonly used to determine a caller's age from their stored date of birth:
 
<code>@27(DA,BD)</code>
 
In this example:
 
* <strong>DA</strong> – Current date
* <strong>BD</strong> – Caller’s date of birth
 
The function returns the number of full calendar years between the two dates.  


Next section: [[using disk drives|Using Disk Drives]]
Next section: [[using disk drives|Using Disk Drives]]


[[programming features|Programming Features]]
[[programming features|Programming Features]]

Latest revision as of 14:08, 7 March 2026

Programming Features - Absolute Day Numbers (ADN)

Absolute Day Numbers (ADN)

The BBS system stores the current date in the numeric variable DA using a format known as an Absolute Day Number (ADN).

An ADN represents the total number of days that have elapsed since January 1, 1800 (01/01/1800). While this representation may seem unusual at first, it greatly simplifies date calculations. The Color 64 machine language routines perform all required conversions automatically, so most programs never need to manipulate the ADN value directly.

Under normal BBS operation, users never see ADN values. However, sysops who write programs or modules should understand how this system works.

Machine language functions @15 through @19 are used internally to perform ADN calculations and conversions. For detailed information about these functions, refer to the section "ML Function Summary".


Date Handling in the Time Routine

The current time routine located at line 1110 of each overlay also manages the system date. When midnight occurs, this routine increments the variable DA by one day. The updated value of DA is then used to calculate the other date-related variables.

The following variables are derived from DA:

Variable Description
DA$ Current date in the format MM/DD/YYYY
D1 Current month (1–12)
D2 Day of week (0–6, where 0 = Sunday and 6 = Saturday)
D3 Day of the month (1–31)
D4 Current year (1800–9999)

The formatted date string DA$ is generated automatically from the ADN value.


Month and Day Name Arrays

Two string arrays are provided for converting dates into readable text:

Array Contents
D1$() Month names, where D1$(1) through D1$(12) correspond to January through December
D2$() Day names, where D2$(0) through D2$(6) correspond to Sunday through Saturday

These arrays allow programs to display dates in plain English format.


Other ADN-Based Variables

Several additional variables store dates internally using ADN format:

Variable Description
ED Caller's membership expiration date
LD Caller's last call date
BD Caller's date of birth

When user information is read from the password file, the corresponding formatted string variables are also generated automatically:

  • ED$ – Membership expiration date (formatted)
  • LD$ – Last call date (formatted)
  • BD$ – Date of birth (formatted)


Calculating Differences Between Dates

Because dates are stored as Absolute Day Numbers, calculating the number of days between two dates is simple.

To determine the number of days between two dates:

difference = higher ADN − lower ADN

The result is the exact number of days between the two dates.


Calculating Future Dates

To determine the date after a specific number of days, simply add the desired number of days to the current ADN value:

future_date = DA + number_of_days

The resulting ADN can then be converted back into formatted date variables using the standard system routines.


Calculating Age or Year Differences

Machine language function @27 calculates the number of calendar years between two ADN values.

This function is commonly used to determine a caller's age from their stored date of birth:

@27(DA,BD)

In this example:

  • DA – Current date
  • BD – Caller’s date of birth

The function returns the number of full calendar years between the two dates.

Next section: Using Disk Drives

Programming Features