LNGDTE16.DLL - Long Integer date functions to replace Visual Basic Variant Dates Copyright 1996, DollarMark Systems, Inc. INTRODUCTION LNGDTE16 is a 16-bit DLL that replaces Visual Basic's date manipulation functions allowing effecient storage of dates as long integers instead of variants. The functions in the DLL outperform VB3's functions by factors ranging from 2X to 15X. The DLL outperforms VB4 by factors ranging from 5X to 100X ! Visual Basic requires the use of variant data type for date manipulations. In addition to the variant overhead, the date is internally represented as a double precision value, with the integer portion representing the date and the fractional portion representating time. LNGDTE16.DLL simplifies calculations where variants are not desired and the time parameter is not required. They are especially beneficial in simulations where dates must be repeatedly compared or manipulated. These functions can also be called from other languages that may not have equivalent date manipulation functions. These functions, like VB, define 12/31/1899 to have a long integer value of 1. The DLL functions provide identical performance to VB functions for dates ranging from 12/31/1899 to 12/31/9999. Dates prior to 12/31/1899 (having negative integer values) are not supported in this version of the DLL. The DLL does correctly handle all leap years, including special handling of the centennials. (e.g. 2000, 2100) VB functions replicated are: DateAdd, DateDiff, DatePart, DateSerial, Year, Month, and Day. The DLL functions have the same name as VB, but are preceeded with the prefix 'lng'. For example, the DLL equivalent for DateAdd() is lngDateAdd(). The DLL also provides additional functions where the specification of the date interval (e.g. "yyyy" for Year) is passed as an integer value instead of as a string value. These functions all have a '2' suffix. (e.g. DateAdd2()). The functions without the string parameters are 2-5X faster than their string counterparts. In addition, the DLL provides an additional function MDYParts(), which will return Year, Month, and Day for a given long integer date value. This function allows breaking down a integer date value into all components parts with one function call. The DLL does no date formatting nor will it accept string date formats (e.g. "6/12/1996"). Therefore, it does not need to consider international settings. Any text date entries must be converted to dates and then to longs in order to use the DLL routines. e.g. CLng(CvDate("6/12/1996")) Likewise, long integer dates must be converted before printing - CvDate(dlldte&). If any invalid values are passed to DLL functions, the returned date value will be zero to signify an error occurred. Possible errors are calculations resulting in a date value prior to 12/31/1899 or after 12/31/9999; specification of invalid dates in DateSerial (eg. 2/31/96, 34/1/96). DATE INTERVALS AND INTEGER EQUIVALENTS The string specifications for date intervals are indentical to VB's. Constants definitions are provided in DTEDECL.BAS, along with Function declarations. Interval String Representation Int. Const Int Value ================================================================= Year yyyy D_YEAR 1 Month m D_MONTH 2 Day d D_DAY 3 WeekDay w D_WEEKDAY 4 Day of Year y D_DAYOFYEAR 5 Week w D_WEEK 6 Quarter q D_QUARTER 7 FUNCTION DESCRIPTIONS Declare Function LngDateAdd Lib "LNGDTE16.DLL" (ByVal iv$, ByVal num&, ByVal dte1&) As Long Declare Function lngDateAdd2 Lib "LNGDTE16.DLL" (ByVal Intv%, ByVal num&, ByVal dte1&) As Long - Add num intervals to date in dte1&. Declare Function lngDateDiff Lib "LNGDTE16.DLL" (ByVal iv$, ByVal dte1&, ByVal Dte2&) As Long Declare Function lngDateDiff2 Lib "LNGDTE16.DLL" (ByVal Intv%, ByVal dte1&, ByVal Dte2&) As Long - returns number of intervals between dte1 and dte2 Declare Function lngDatePart Lib "LNGDTE16.DLL" (ByVal iv$, ByVal dte1&) As Long Declare Function lngDatePart2 Lib "LNGDTE16.DLL" (ByVal Intv%, ByVal dte1&) As Long - returns the specified interval for Dte1 Declare Function lngDateSerial Lib "LNGDTE16.DLL" (ByVal year%, ByVal month%, ByVal day%) As Long - returns a long integer value corresponding to year, month, and day. if any value of year, month, or day is invalid, function returns 0. Declare Function lngMDYParts Lib "LNGDTE16.DLL" (ByVal Dte&, year%, month%, day%) As Integer - for a given long integer dte, the function calculates corresponding values for year, month, and day. If Dte is outside the valid date range, function returns 1; if dte is valid, function returns 0. Declare Function lngYear Lib "LNGDTE16.DLL" (ByVal Dte&) As Integer Declare Function lngMonth Lib "LNGDTE16.DLL" (ByVal Dte&) As Integer Declare Function lngDay Lib "LNGDTE16.DLL" (ByVal Dte&) As Integer - for a given long integer dte, these functions return corresponding values for year, month, or day. Functionally Indentical to DatePart, but without requiring the interval parameter. Global Const LD_YEAR = 1 Global Const LD_MONTH = 2 Global Const LD_DAY = 3 Global Const LD_WEEKDAY = 4 Global Const LD_DAYOFYEAR = 5 Global Const LD_WEEK = 6 Global Const LD_QUARTER = 7 SHAREWARE REGISTRATION If you find this DLL useful to your applications, please register! The registration fee is $12 (USD). Registration entitles you to free updates of the DLL (including a 32-bit version when it becomes available). I will consider any requests for additional functions to add to the DLL. Registration may be done through CompuServe, GO SWREG. My registration ID# is: TBD - search for CompuServe ID 72223,1637 in author's user ID after 6/5/96 Or send registration fee and comments to: DollarMark Systems, Inc. 1605 21st Street South Birmingham, AL 35205 72223.1637@compuserve.com