home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / DATETP.ZIP / DATE.DOC < prev    next >
Encoding:
Text File  |  1986-08-09  |  3.4 KB  |  63 lines

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