GRE2DAY& PowerBASIC Function |
GRE2DAY& function evaluates to the absolute day number that corresponds to the Gregorian date specified as its parameter. Date should be specified in one of the formats MM-DD-YY or MM-DD-CCYY and should be a valid date in Gregorian calendar. If parameter doesn't represent a valid date, 0 (zero) is returned instead of absolute day number. If century is omitted, the current century is assumed. Date field delimiters are expected to be in the fixed positions 3 and 5; values of delimiters are insignificant. If parameter is empty, absolute day number is returned for the current date. 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 GRE2DAY& function is intended for the modern-time date calculations, those factors are insignificant. Direct dependency:
Indirect dependencies:
GRE2DAY& Source Program Debugging program Debugging logout |
' GRE2DAY&(0.0) Convert Gregorian Date to Day Number 02/01/1989-10/15/2004 ' -------------------------------------------------------------------------- ' Copyright (C) 1989-2004 by Vladimir Veytsel www.davar.net ' Type --------------------------------------------------------------------- ' Function ' Description -------------------------------------------------------------- ' GRE2DAY& function converts Gregorian date into absolute day number. ' Declaration -------------------------------------------------------------- ' DECLARE FUNCTION GRE2DAY&(Greg.Date$) ' Parameter ---------------------------------------------------------------- ' Greg.Date$ - Gregorian date in the form of MM-DD-YY or MM-DD-CCYY ' Value -------------------------------------------------------------------- ' If specified Gregorian date is either EMPTY or valid, i.e.: ' it has length either of 8 or 10 characters and ' it is DIGITAL (with the exception of date field delimiters) and ' month value lies within 1-12 and ' day number lies within range valid for the specified month ' (considering specified year leap characteristic when ' evaluating day range for February), ' then absolute day number for specified Gregorian date is returned ' to the point of function invocation ' else 0 (zero) is returned to the point of invocation. ' Notes -------------------------------------------------------------------- ' - Delimiters of parameter date fields are irrelevant and can be any ' symbols. Date fields are extracted from fixed positions. ' - EMPTY date is considered to be a valid one, and absolute A.D. day ' number is returned for the CURRENT date (default). ' - 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 ----------------------------------------------------------------- ' GRE2DAY&("*" )= 0 ' GRE2DAY&("" )= Absolute day number for the current date ' GRE2DAY&("01-01-0001")= 1 ' GRE2DAY&("12-31-0001")= 365 ' GRE2DAY&("01-01-0002")= 366 ' GRE2DAY&("12-31-0002")= 730 ' GRE2DAY&("01-01-0003")= 731 ' GRE2DAY&("12-31-0003")= 1095 ' GRE2DAY&("01-01-0004")= 1096 ' GRE2DAY&("12-31-0004")= 1461 ' GRE2DAY&("01-01-0005")= 1462 ' GRE2DAY&("12-31-1986")= 725371 ' GRE2DAY&("01-01-1987")= 725372 ' GRE2DAY&("12-31-1987")= 725736 ' GRE2DAY&("01-01-1988")= 725737 ' GRE2DAY&("12-31-1899")= 693595 ' GRE2DAY&("01-01-1900")= 693596 ' GRE2DAY&("12-31-1999")= 730119 ' GRE2DAY&("01-01-00" )= 730120 ' External Function -------------------------------------------------------- DECLARE FUNCTION GRE2JUL$(Greg.Date$) ' Start Function ----------------------------------------------------------- DEFINT A-Z ' All defaulted variables are integer FUNCTION GRE2DAY&(Greg.Date$) PUBLIC ' Convert Gregorian Date to Julian Format ---------------------------------- ' (Checks date validity and handles default empty date - current) Jul.Date$=GRE2JUL$(Greg.Date$) IF (LEN(Jul.Date$)=0) THEN GRE2DAY&=0 EXIT FUNCTION END IF ' Add Current Century to Short Date (YY-DDD) ------------------------------- IF (LEN(Jul.Date$)=6) THEN Jul.Date$=MID$(DATE$,7,2)+Jul.Date$ END IF ' Parse Date to Be Converted ----------------------------------------------- Day =VAL(RIGHT$(Jul.Date$,3)) Year =VAL( LEFT$(Jul.Date$,4))-1 ' First day of A.D. is 01-01-0001 Century=INT(Year/100) ' Compute and Return Absolute Day Number to the Point of Invocation -------- GRE2DAY&=Year*365+Day+INT(Year/4)-Century+INT(Century/4) ' Finish.Function ---------------------------------------------------------- END FUNCTION
GRE2DAY& Debugging Program Source program Debugging logout |
' GRE2DAY&(0.0) Convert Gregorian Date to Day Number 02/01/1989-10/15/2004 ' -------------------------------------------------------------------------- $INCLUDE "GRE2DAY" $LINK "MODULE.PBL" DECLARE FUNCTION GRE2DAY&(Greg.Date$) CLS PRINT "GRE2DAY&(0.0) Convert Gregorian Date to Absolute Day Number ";DATE$; PRINT " ";LEFT$(TIME$,5) PRINT STRING$(79,"-") PRINT PRINT "GRE2DAY&('*' )="; _ GRE2DAY&("*" ) PRINT "GRE2DAY&('' )="; _ GRE2DAY&("" );" - Today ";DATE$ PRINT "GRE2DAY&('01-01-0001')="; _ GRE2DAY&("01-01-0001") PRINT "GRE2DAY&('12-31-0001')="; _ GRE2DAY&("12-31-0001") PRINT "GRE2DAY&('01-01-0002')="; _ GRE2DAY&("01-01-0002") PRINT "GRE2DAY&('12-31-0002')="; _ GRE2DAY&("12-31-0002") PRINT "GRE2DAY&('01-01-0003')="; _ GRE2DAY&("01-01-0003") PRINT "GRE2DAY&('12-31-0003')="; _ GRE2DAY&("12-31-0003") PRINT "GRE2DAY&('01-01-0004')="; _ GRE2DAY&("01-01-0004") PRINT "GRE2DAY&('12-31-0004')="; _ GRE2DAY&("12-31-0004") PRINT "GRE2DAY&('01-01-0005')="; _ GRE2DAY&("01-01-0005") PRINT "GRE2DAY&('12-31-1986')="; _ GRE2DAY&("12-31-1986") PRINT "GRE2DAY&('01-01-1987')="; _ GRE2DAY&("01-01-1987") PRINT "GRE2DAY&('12-31-1987')="; _ GRE2DAY&("12-31-1987") PRINT "GRE2DAY&('01-01-1988')="; _ GRE2DAY&("01-01-1988") PRINT "GRE2DAY&('12-31-1899')="; _ GRE2DAY&("12-31-1899") PRINT "GRE2DAY&('01-01-1900')="; _ GRE2DAY&("01-01-1900") PRINT "GRE2DAY&('12-31-1999')="; _ GRE2DAY&("12-31-1999") PRINT "GRE2DAY&('01-01-00' )="; _ GRE2DAY&("01-01-00" );" - Today's century" PRINT PRINT "Execution completed - hit [Enter] to continue..."
GRE2DAY& Debugging Logout Source program Debugging program |
GRE2DAY&(0.0) Convert Gregorian Date to Absolute Day Number 10-15-2004 08:38 ------------------------------------------------------------------------------- GRE2DAY&('*' )= 0 GRE2DAY&('' )= 731869 - Today 10-15-2004 GRE2DAY&('01-01-0001')= 1 GRE2DAY&('12-31-0001')= 365 GRE2DAY&('01-01-0002')= 366 GRE2DAY&('12-31-0002')= 730 GRE2DAY&('01-01-0003')= 731 GRE2DAY&('12-31-0003')= 1095 GRE2DAY&('01-01-0004')= 1096 GRE2DAY&('12-31-0004')= 1461 GRE2DAY&('01-01-0005')= 1462 GRE2DAY&('12-31-1986')= 725371 GRE2DAY&('01-01-1987')= 725372 GRE2DAY&('12-31-1987')= 725736 GRE2DAY&('01-01-1988')= 725737 GRE2DAY&('12-31-1899')= 693595 GRE2DAY&('01-01-1900')= 693596 GRE2DAY&('12-31-1999')= 730119 GRE2DAY&('01-01-00' )= 730120 - Today's century Execution completed - hit [Enter] to continue... |
View [and save] GRE2DAY.BAS text View [and save] ZGRE2DAY.BAS text (Use [Back] button or [Alt]+[CL] to return here from the viewed text) Copyright © 1988–2004 by Go to: Davar site entry | Site contents | Site index | Personal Computer | PowerBASIC | Text top |