Visual Basic

Visual Basic Programmer's Guide to Successful Dating

The Gregorian calendar, which is used throughout the western world, has a long and checkered past. It was first introduced in 1582 by Pope Gregory XIII, after whom it is named.

A Little About the Date Rules

Prior to the Gregorian calendar the Julian calendar was widely used. The Julian calendar had a leap year every four years. With the actual period of our orbit around the sun being 365.24219 days, there was a slow shifting of the seasons, until by the sixteenth century events such as the autumnal equinox were occurring up to ten days earlier than they were when the Julian calendar was introduced. The Gregorian calendar changed the rule for the century years so that they would not be leap years unless they were divisible by 400.

The new calendar was adopted in Catholic countries in 1582. Ten days were dropped to bring the seasons back into line. October 4 was immediately followed by October 15, with no dates in between. The United Kingdom and its colonies, which at the time included areas of North America, made the change in 1752 with the dropping of eleven days (September 2 was immediately followed by September 14).

NOTE
Every fourth year is a leap year except those that are also divisible by 100. However, those years divisible by 400 are leap years. So the year 2000 is a leap year; 1900 and 2100 are not.

So How Does Visual Basic Help My Dating Success?

Here are some ways Visual Basic helps you get around the Year 2000 glitch.

The Date Data Type

Visual Basic has had a dedicated Date data type since version 4 and, prior to that (in versions 2 and 3) a Date Variant type with the same storage pattern. Dates can be declared and used like this:

Dim dteMyDate     As Date
  dteMyDate = DateSerial(1998, 2, 12)

Or perhaps

dteMyDate = #2/12/98#

The Date data type is actually stored as an IEEE double-precision floating point value, 8 bytes long. The data stored can represent dates from January 1 100 up to December 31 9999. Days are stored as whole numbers, with zero being December 30 1899. Dates prior to this are stored as negative values, those after are positive. In the example above, February 12 1998 is stored as 35838. You can test this outcome with the following code:

MsgBox CDbl(DateSerial(1998, 2, 12))

The Date data type is also able to hold time information. Hours, minutes, and seconds are held as fractions, with noon represented as 0.5. If we take the number of seconds in a day, 86400, and divide that into 1, the answer is the fraction equal to one second: 0.000011574…. The table below shows the minimum, default, and maximum values that can be stored in a variable declared as a Date.

Date Value Stored
Minimum Value January 1 100 00:00:00 -657434
Default Value December 30 1899 00:00:00 0
Maximum Value December 31 9999 23:59:59 2958465.99998843

As we can see, there is nothing wrong with the way Visual Basic stores dates. Its method is both compact and Year 2000 compliant. For example, 8 bytes would store only the date if encoded as an alphanumeric CCYYMMDD. In effect, the Date data type allows us to store the time for free.