Go to:  Davar site entry | Site contents | Site index | Personal Computer | PowerBASIC | Text bottom

DAY2GRE$  PowerBASIC  Function

         

DAY2GRE$ function evaluates to the date in Gregorian format (MM-DD-CCYY) that corresponds to the absolute date number specified as its parameter.  If parameter is 0 (zero), "" (empty string) is returned instead of Gregorian date value.

Note:  Program doesn't take into account pre-Gregorian (Julian) calendar differences and date adjustment made on 09/14/1752 when England and its colonies switched from Julian calendar to currently used Gregorian. Since DAY2GRE$ function is intended for the modern-time date calculations, those factors are insignificant.

Direct dependencies:

JUL2GRE$ Convert Julian date into Gregorian date format
LEAP% Check year for leap value (predicate)

Indirect dependency:

DIGITAL% Check character string for digital value (predicate)



 DAY2GRE$  Source  Program                       Debugging program             Debugging logout

      ' DAY2GRE$(0.0)  Convert Day Number to Gregorian Date  02/01/1989-10/15/2004
      ' --------------------------------------------------------------------------
      ' Copyright (C) 1989-2004 by Vladimir Veytsel                  www.davar.net

      ' Type ---------------------------------------------------------------------

      '    Function

      ' Description --------------------------------------------------------------

      '    DAY2GRE$ function converts absolute day number into Gregorian date.

      ' Declaration --------------------------------------------------------------

      '    DECLARE FUNCTION DAY2GRE$(Day.Numb&)

      ' Parameter ----------------------------------------------------------------

      '    Day.Numb&  - Gregorian date in the form of MM-DD-YY or MM-DD-CCYY

      ' Value --------------------------------------------------------------------

      '    If specified absolute day number is greater than zero,
      '       then corresponding MM-DD-CCYY (date in Gregorian format) is returned
      '            to the point of function invocation
      '       else "" (empty string) is returned to the point of invocation.

      ' Note ---------------------------------------------------------------------

      '  - Program doesn't take into account pre-Gregorian (Julian)calendar
      '    differences and date adjustment made on 09/14/1752 - when England
      '    and its colonies switched from Julian calendar to currently used
      '    Gregorian.  Since program is intended for the modern-time date
      '    calculations, those factors are insignificant.

      ' Examples -----------------------------------------------------------------

      '    DAY2GRE$(     0)=""
      '    DAY2GRE$(     1)="01-01-0001"
      '    DAY2GRE$(   365)="12-31-0001"
      '    DAY2GRE$(   366)="01-01-0002"
      '    DAY2GRE$(   730)="12-31-0002"
      '    DAY2GRE$(   731)="01-01-0003"
      '    DAY2GRE$(  1095)="12-31-0003"
      '    DAY2GRE$(  1096)="01-01-0004"
      '    DAY2GRE$(  1460)="12-30-0004"
      '    DAY2GRE$(  1461)="12-31-0004"
      '    DAY2GRE$(  1462)="01-01-0005"
      '    DAY2GRE$(725371)="12-31-1986"
      '    DAY2GRE$(725372)="01-01-1987"
      '    DAY2GRE$(725736)="12-31-1987"
      '    DAY2GRE$(725737)="01-01-1988"
      '    DAY2GRE$(693595)="12-31-1899"
      '    DAY2GRE$(693596)="01-01-1900"
      '    DAY2GRE$(730119)="12-31-1999"
      '    DAY2GRE$(730120)="01-01-2000"

      ' External Functions -------------------------------------------------------

           DECLARE FUNCTION JUL2GRE$(Jul.Date$)
           DECLARE FUNCTION LEAP%   (Year$)

      ' Start Function -----------------------------------------------------------

           DEFINT A-Z  ' All defaulted variables are integer

           FUNCTION DAY2GRE$(Day.Numb&) PUBLIC

      ' Check Day Number Validity ------------------------------------------------

           IF (Day.Numb&<=0) THEN
              DAY2GRE$=""
              EXIT FUNCTION
           END IF

      ' Compute Components of Julian Date (Year and Day) -------------------------

           Year=1  ' First day of A.D. is 01-01-0001

           WHILE (Day.Numb&>365)
                 Day.Numb&=Day.Numb&-365+LEAP%(RIGHT$("000"+LTRIM$(STR$(Year)),4))
                 Year=Year+1
           WEND

      ' Adjust Date for 12/31 of Leap Year ---------------------------------------

           IF (Day.Numb&=0)AND _
              (LEAP%(RIGHT$("000"+LTRIM$(STR$(Year-1)),4))) THEN
              Day.Numb&=366
              Year=Year-1
           END IF

      ' Compose, Convert, and Return Gregorian Date to the Point of Invocation ---

           DAY2GRE$=JUL2GRE$(RIGHT$("000"+LTRIM$(STR$(Year     )),4)+"-"+ _
                             RIGHT$("00" +LTRIM$(STR$(Day.Numb&)),3))

      ' Finish.Function ----------------------------------------------------------

           END FUNCTION
  
         

 DAY2GRE$  Debugging  Program                     Source program             Debugging logout

      ' DAY2GRE$(0.0)  Convert Day Number to Gregorian Date  02/01/1989-10/15/2004
      ' --------------------------------------------------------------------------

        $INCLUDE "DAY2GRE"
        $LINK    "MODULE.PBL"

        DECLARE FUNCTION DAY2GRE$(Day.Numb&)

        CLS
        PRINT "DAY2GRE$(0.0)  Convert Absolute Day Number to Gregorian Date  ";DATE$;
        PRINT "  ";LEFT$(TIME$,5)
        PRINT STRING$(79,"-")
        PRINT

        PRINT "DAY2GRE$(     0)='"; _
               DAY2GRE$(     0);"'"
        PRINT "DAY2GRE$(     1)='"; _
               DAY2GRE$(     1);"'"
        PRINT "DAY2GRE$(   365)='"; _
               DAY2GRE$(   365);"'"
        PRINT "DAY2GRE$(   366)='"; _
               DAY2GRE$(   366);"'"
        PRINT "DAY2GRE$(   730)='"; _
               DAY2GRE$(   730);"'"
        PRINT "DAY2GRE$(   731)='"; _
               DAY2GRE$(   731);"'"
        PRINT "DAY2GRE$(  1095)='"; _
               DAY2GRE$(  1095);"'"
        PRINT "DAY2GRE$(  1096)='"; _
               DAY2GRE$(  1096);"'"
        PRINT "DAY2GRE$(  1460)='"; _
               DAY2GRE$(  1460);"'"
        PRINT "DAY2GRE$(  1461)='"; _
               DAY2GRE$(  1461);"'"
        PRINT "DAY2GRE$(  1462)='"; _
               DAY2GRE$(  1462);"'"
        PRINT "DAY2GRE$(725371)='"; _
               DAY2GRE$(725371);"'"
        PRINT "DAY2GRE$(725372)='"; _
               DAY2GRE$(725372);"'"
        PRINT "DAY2GRE$(725736)='"; _
               DAY2GRE$(725736);"'"
        PRINT "DAY2GRE$(725737)='"; _
               DAY2GRE$(725737);"'"
        PRINT "DAY2GRE$(693595)='"; _
               DAY2GRE$(693595);"'"
        PRINT "DAY2GRE$(693596)='"; _
               DAY2GRE$(693596);"'"
        PRINT "DAY2GRE$(730119)='"; _
               DAY2GRE$(730119);"'"
        PRINT "DAY2GRE$(730120)='"; _
               DAY2GRE$(730120);"'"
        PRINT
        PRINT "Execution completed - hit [Enter] to continue..."
  
         

 DAY2GRE$  Debugging  Logout                           Source program                   Debugging program

         

   DAY2GRE$(0.0)  Convert Absolute Day Number to Gregorian Date  10-15-2004  17:59
   -------------------------------------------------------------------------------

   DAY2GRE$(     0)=''
   DAY2GRE$(     1)='01-01-0001'
   DAY2GRE$(   365)='12-31-0001'
   DAY2GRE$(   366)='01-01-0002'
   DAY2GRE$(   730)='12-31-0002'
   DAY2GRE$(   731)='01-01-0003'
   DAY2GRE$(  1095)='12-31-0003'
   DAY2GRE$(  1096)='01-01-0004'
   DAY2GRE$(  1460)='12-30-0004'
   DAY2GRE$(  1461)='12-31-0004'
   DAY2GRE$(  1462)='01-01-0005'
   DAY2GRE$(725371)='12-31-1986'
   DAY2GRE$(725372)='01-01-1987'
   DAY2GRE$(725736)='12-31-1987'
   DAY2GRE$(725737)='01-01-1988'
   DAY2GRE$(693595)='12-31-1899'
   DAY2GRE$(693596)='01-01-1900'
   DAY2GRE$(730119)='12-31-1999'
   DAY2GRE$(730120)='01-01-2000'

   Execution completed - hit [Enter] to continue...
        
      

         

View [and save] DAY2GRE.BAS text       View [and save] ZDAY2GRE.BAS text
(Use [Back] button or [Alt]+[CL] to return here from the viewed text)
To make DAY2GRE.BAS source text compilable
change globally of "&lt;" into "<" signs.
Copyright © 19882004 by
Go to:  Davar site entry | Site contents | Site index | Personal Computer | PowerBASIC | Text top