Home DFS SB OD SDN DFSM THP Donate $5

Notice: How To Tip The Webmaster.


You are at the section Gregorian to Julian Calendar Conversion

Gregorian to Julian Calendar Conversion

Here's the PowerBasic program I wrote that would convert a Gregorian Calendar Date into a Julian Calendar Date.

You could convert this script into another progrmaming language. This program may have bugs.

REM positive/negative integers: replace all variables that are an INTEGER % with LONG & or QUAD && - done
REM positive only integers: replace all variables that are a BYTE ? and WORD ?? with DWORD ??? - done
REM floating point numbers: replace all variables that are a SINGLE ! with DOUBLE # or EXTENDED ## - ?
REM Calculate Julian Day from Gregorian Date or Julian Date
REM revised July 26, 2025

#COMPILE EXE
#DIM ALL

FUNCTION PBMAIN () AS LONG
CLS
CONSOLE NAME "Gregorian Date to Julian Day"
ON ERROR GOTO termination
' SET THE SCREEN SIZE (replace the numbers with other values)
CON.SCREEN = 60&,120&
CON.LOC = 0&,0&
REM ShowWindow CONSHNDL, %SW_SHOWMAXIMIZED
' WHAT DRIVE LETTER ARE YOU USING
LOCAL FullCurrentPath$: GLOBAL CurrentDrive$: FullCurrentPath$ = CURDIR$
IF MID$(CURDIR$,2,1) = ":" THEN CurrentDrive$ = LEFT$(CURDIR$,2)
' PRINT CurrentDrive$

DIM gyear AS DOUBLE, gmonth AS DOUBLE, gday AS DOUBLE, gcalendar$, bcad$
DIM calcy AS DOUBLE, calcd AS DOUBLE, calcn AS DOUBLE, calcg AS DOUBLE
DIM jdn1 AS DOUBLE
DIM gyear2 AS DOUBLE: REM the year number of the year beginning on March 1 (one less in Jan and Feb)
DIM gmonth2 AS DOUBLE: REM month number where March = 0, January = 10 and February = 11
DIM question$

PRINT "Convert Gregorian Date to Julian Day"
  DO
    PRINT "(B).C. or (A).D.?"
    INPUT bcad$
    bcad$ = UCASE$(bcad$)
  LOOP UNTIL bcad$ = "B" OR bcad$ = "A"
  IF bcad$ = "A" THEN
    DO
      PRINT "Input the Year (Valid range 1 to 3267 AD)"
      INPUT gyear
      gyear = INT(gyear)
    LOOP UNTIL gyear <= 3267 AND gyear >= 1
  ELSEIF bcad$ = "B" THEN
    DO
      PRINT "Input the Year (Valid range 1 to 4714 BC)"
      PRINT "Do not enter the number as a negative number!"
      PRINT "Do not add or subtract from the original BC year!"
      PRINT "Computer will convert the BC year to a negative number plus one."
      INPUT gyear
      gyear = INT(gyear)
    LOOP UNTIL gyear <= 4714 AND gyear >= 1
    gyear = (gyear * -1) + 1
  END IF
  DO
    PRINT "Input the Month number (1-12)"
    INPUT gmonth
    gmonth = INT(gmonth)
  LOOP UNTIL gmonth > 0 AND gmonth < 13
  DO
    PRINT "Input the Day of the Month (1-31)"
    INPUT gday
    gday = INT(gday)
  LOOP UNTIL gday > 0 AND gday < 32
  DO
    PRINT "Input"
    PRINT " 0 = unknown calendar style"
    PRINT " 1 = Gregorian"
    PRINT " 2 = unspecified Old Julian calendar style"
    PRINT " C = J+CD (Julian-12-25+, the Dec 25 before the Julian-1 number change day."
    PRINT " J = Ju-1 (Julian-1)"
    PRINT " L = J-LD (Julian-3-25-, the March 25 after the Julian-1 number change day."
    PRINT " M = Ju-3 (Julian-3-, the March 1 after the Julian-1 number change day."
    PRINT " N = Ju+9 (Julian-9-1+, the Sep. 1 before the Julian-1 number change day."
    PRINT ""
    INPUT gcalendar$
    gcalendar$ = UCASE$(gcalendar$): question$ = " "
    IF gcalendar$ = "0" THEN
      IF gyear > 1752 THEN
        gcalendar$ = "1": question$ = "?": PRINT "Using Julian(?) Calendar"
      ELSEIF gyear = 1752 THEN
        IF gmonth > 9 THEN
          gcalendar$ = "1": question$ = "?": PRINT "Using Julian(?) Calendar"
        ELSEIF gmonth = 9 THEN
          IF gday > 2 THEN
            gcalendar$ = "1": question$ = "?": PRINT "Using Julian(?) Calendar"
          ELSE
            gcalendar$ = "J": question$ = "?": PRINT "Using Julian(?) Calendar"
          END IF
        ELSE
          gcalendar$ = "J": question$ = "?": PRINT "Using Julian(?) Calendar"
        END IF
      ELSE
        gcalendar$ = "J": question$ = "?": PRINT "Using Julian(?) Calendar"
      END IF
    END IF
    IF gcalendar$ = "2" THEN
      gcalendar$ = "J": question$ = "?": PRINT "Using Julian(?) Calendar"
    END IF
    IF gcalendar$ = "C" THEN
      IF gmonth = 12 AND gday > 24 THEN
        gyear = gyear - 1
      END IF
      gcalendar$ = "J": PRINT "Using Julian Calendar"
    END IF
    IF gcalendar$ = "N" THEN
      IF gmonth > 8 THEN
        gyear = gyear - 1
      END IF
      gcalendar$ = "J": PRINT "Using Julian Calendar"
    END IF
    IF gcalendar$ = "M" THEN
      IF gmonth < 3 THEN
        gyear = gyear + 1
      END IF
      gcalendar$ = "J": PRINT "Using Julian Calendar"
    END IF
    IF gcalendar$ = "L" THEN
      IF gmonth < 3 THEN
        gyear = gyear + 1
      ELSEIF gmonth = 3 THEN
        IF gday < 25 THEN
          gyear = gyear + 1
        END IF
      END IF
      gcalendar$ = "J": PRINT "Using Julian Calendar"
    END IF
  LOOP UNTIL gcalendar$ = "1" OR gcalendar$ = "J"

  IF gmonth = 2 AND gday > 29 THEN gday = 29
  IF gmonth = 4 AND gday > 30 THEN gday = 30
  IF gmonth = 6 AND gday > 30 THEN gday = 30
  IF gmonth = 9 AND gday > 30 THEN gday = 30
  IF gmonth = 11 AND gday > 30 THEN gday = 30
  IF gmonth = 2 AND gday = 29 THEN
    IF INT(gyear/4)*4 <> gyear THEN
      gday = 28
    END IF
    IF gcalendar$ = "1" THEN
      IF INT(gyear/400)*400 <> gyear AND INT(gyear/100)*100 = gyear THEN
        gday = 28
      END IF
    END IF
  END IF

' a = the year of the common era gyear
' m = the month reckoned from January = 1 to December = 12 as gmonth
' d = the day of the month as gday
  gyear2 = gyear - INT((12 - gmonth)/10): PRINT gyear, gyear2
  gmonth2 = (gmonth + 9) MOD 12: PRINT gmonth, gmonth2
' gyear = gyear2 + INT(gmonth2/10)
' gmonth = ((gmonth2 + 2) MOD 12) + 1
' replaces:
' if gmonth = 1 or gmonth = 2 then
'   gyear2 = gyear2 - 1: gmonth2 = gmonth2 + 9
' else
'   gmonth2 = gmonth2 - 3
' end if
  calcy = INT(365.25 * (gyear2 + 4712))
  calcd = INT((30.6 * gmonth2) + 0.5)
  calcn = calcy + calcd + gday + 59 - 0.5

REM if the date is in the Julian calendar
  IF gcalendar$ = "J" THEN
    jdn1 = calcn
    PRINT "Julian Date to JPD at 12AM = "; jdn1
    PRINT "Julian Date to JPD at  6AM = "; jdn1 + 0.25
    PRINT "Julian Date to JPD at 12PM = "; jdn1 + 0.5
    PRINT "Julian Date to JPD at  6PM = "; jdn1 + 0.75
    PRINT "Date: "; gyear; "-"; gmonth; "-"; gday
    PRINT "Date2: "; gyear2; "-"; gmonth2; "-"; gday
  ELSEIF gcalendar$ = "1" THEN
    calcg = INT(INT((gyear2/100) + 49) * 0.75) - 38
    jdn1 = calcn - calcg
    PRINT "Gregorian Date to JPD at 12AM = "; jdn1
    PRINT "Gregorian Date to JPD at  6AM = "; jdn1 + 0.25
    PRINT "Gregorian Date to JPD at 12PM = "; jdn1 + 0.5
    PRINT "Gregorian Date to JPD at  6PM = "; jdn1 + 0.75
    PRINT "Date: "; gyear; "-"; gmonth; "-"; gday
    PRINT "Date2: "; gyear2; "-"; gmonth2; "-"; gday
  END IF



  WAITKEY$


REM  July 25, 2025 Gregorian = Julian Date 2460881 at 12pm
REM (-0.5 at 12am, +0.5 at 12am the following date.)

EXIT FUNCTION
END FUNCTION
Menu:
Silicon Cajon Home Page DavesFunStuff
Footer:
Dave's Fun Stuff Super Birthdays



© 1995-2026. davesfunstuff.com. All Rights Reserved. Reproduction of any part of this website without expressed written consent is prohibited.

Help Support Our Ad-Free Web Section

Just use our PayPal link to pay.

Please Donate Cash to help pay for webhosting, domain payments, expenses and labor in keeping this section going. Thank you.

$2, $5, $10, $20, $50, $75, $100, $ANY

Notice Of Disclosure (updated June 2023):

"David Tanny is the owner and operator of the domains davesfunstuff.com and davidtanny.com"

Website Cookie Policy