home *** CD-ROM | disk | FTP | other *** search
- IBMSIG - The Source - Updated: 9 August 1986
-
- Date Conversion from Gregorian (MM/DD/YYYY) format to Julian and Julian to
- Gregorian.
-
- The ability to manipulate dates is needed in some programs for purposes such
- as to compare one date to another to determine which is greater or to
- calculate the number of days between date or to search a file based on a range
- of dates.
-
- This ability is provided in many systems such as dBASE III and Lotus 1-2-3 by
- storing dates in the system as the number of days which have occurred from 1
- January 1900, starting with that date being number 0. This gives you the
- ability to subtract one date from another and arrive at the exact number of
- days between them, add or subtract a number of days to or from a date and
- determine the date of the resulting number.
-
- In this number system the julian number for the date of this file, 9 Aug 1986,
- is 31,632. If you subtract 30 from this number you end up with 31,602 but the
- question then becomes, "What is the date for that day?" It is 7/10/86. Thirty
- days before today was 10 July 1986. That is because July has 31 days.
-
- The accompanying BASIC program provides a very few lines of code that are a
- function to take three numbers for the year, month, and day and convert them
- to the julian number. There are also a few lines of code that take this
- julian number and turn it into the numbers for the year, month and day. It
- also provides a conversion for day of the week such as Monday, etc. and the
- julian day of the year, January 1 is number 1.
-
- If you would prefer to enter and display your dates using the month names, all
- you need to add is an array running from 1 to 12 for January (or JAN) through
- December (or DEC) and substitute that character string for the number of the
- month. You can convert the year and day to string variables and then
- construct a string that prints the day in any format you desire. The reverse
- would be used to accept input using the month name instead of numbers.
-
- The julian number is a single precision number so that it can be used to
- represent dates up to 31 December 9999 (2,958,524 in julian number) and back
- to 1 January -999 (-1,058,859 in julian number). The julian number is the
- number that you would store in your data files. Any time a date is to be
- printed, you perform the conversion from julian number to Year, Month, and Day
- and then print it in the format you desire. Any time a date is to be input
- into the database, you convert the date to julian number and store it in the
- file. Any time you need to perform searches of dates, you convert the date or
- date range for which you are searching into julian number and perform the
- operations on that (or those) number.
-
- Ben Bacon has converted this algorithm into Turbo Pascal. The program is
- named TPDATE.COM and the source code is in the file TPDATE.PAS, both of which
- are included in this archive. Ben is using this code in the LIBSERCH.COM
- program which is used to provide off-line searching of the LIBSCAN.TXT file
- which contains information about the files in the IBMSIG File Library. Ben
- has provided the SIG members with this program as a programming example and
- for the benefits derived from searching for the files you want to download
- while NOT connected!
-
- Thanks to John L. O'Boyle for the original function and code to convert the
- date to julian and julian number to date!
-
- Mike Todd
- SysOp, IBMSIG
- Source ID: SIG003