<?php
/*
Signed Julian Day Number Calculator
For the span: BC 20000 to AD 20000
LANGUAGE : PHP v8.2.12
AUTHOR : Jay Tanner - 2026
LICENSE : Public Domain
*/
$cYear = date('Y');
$TWidth = '666'; // Table width in pixels.
$w = Filter_Input(INPUT_POST, 'SubmitButton');
if (IsSet($w))
{
$StartBCAD = StrToUpper(trim(Filter_Input(INPUT_POST, 'StartBCAD')));
if ($StartBCAD == '') {$StartBCAD = 'AD';}
$StartBCAD = (substr($StartBCAD,0,1) == 'B')? 'BC':'AD';
$StartYear = trim(Filter_Input(INPUT_POST, 'StartYear'));
if ($StartYear == '') {$StartYear = date('Y');}
$StartYear = SPrintF("%05d", abs($StartYear));
$StartMonth = trim(Filter_Input(INPUT_POST, 'StartMonth'));
if ($StartMonth == '') {$StartMonth = date('m');}
$StartMonth = SPrintF("%02d", $StartMonth);
$StartDay = trim(Filter_Input(INPUT_POST, 'StartDay'));
if ($StartDay == '') {$StartDay = date('d');}
$StartDay = SPrintF("%02d", $StartDay);
}
else
{
$StartBCAD = 'AD';
$StartYear = date('Y'); $StartYear = SPrintF("%05d", abs($StartYear));
$StartMonth = date('m');
$StartDay = date('d');
}
// Fill STOP variables with temporary empty ('') dummy values.
$StopBCAD = $StopYear = $StopMonth = $StopDay = '';
$JorG = 'G'; $JorGStr = 'Gregorian';
// Get start year value.
$StartY = ($StartBCAD == 'BC')? -$StartYear : $StartYear;
$StartY = SPrintF("%05d", abs($StartY));
$StartY = ($StartBCAD == 'BC')? "-$StartY" : $StartY;
// Construct full calendar date string.
$DateString = "$StartBCAD $StartYear/$StartMonth/$StartDay";
// Construct numerical calendar date string.
$YmdString = "$StartY/$StartMonth/$StartDay";
// Compute JD numbers for both calendar systems.
$JDNumJ = JD_Number ($YmdString, 'J');
$JDNumG = JD_Number ($YmdString, 'G');
// Determine calendar Day of Week abbreviation (Sun to Sat).
$DOWs = 'SunMonTueWedThuFriSat';
$DoWStrJ = substr($DOWs, 3*((7+($JDNumJ + 1) % 7) %7),3);
$DoWStrG = substr($DOWs, 3*((7+($JDNumG + 1) % 7) %7),3);
// Compute difference in days between the calendar systems.
$JGDiff = $JDNumG - $JDNumJ;
$s = ($JGDiff <> 1)? 's' : '';
if (!Is_Numeric($JDNumJ) or !Is_Numeric($JDNumG))
{
$OutputJ = $JDNumJ;
$OutputG = $JDNumG;
}
else
{
$OutputJ = " Calendar Date: Yyyyy/mm/dd = $StartY/$StartMonth/$StartDay
Julian Calendar JD Number = $JDNumJ\tDoW = $DoWStrJ";
$OutputG = " Gregorian Calendar JD Number = $JDNumG\tDoW = $DoWStrG
Calendar Difference (G − J) = $JGDiff day$s";
}
print <<< END_OF_HTML_PAGE
<!DOCTYPE HTML>
<head>
<title>Signed Julian Day Number Calculator</title>
<style>
BODY
{background:white; color:b; font-family:Verdana; font-size:11pt;}
INPUT[type='text']::-ms-clear {width:0; height:0;}
INPUT[type='text']
{
background:white; color:black; font-family:monospace; font-size:13pt;
font-weight:bold; text-align:center;
border:2px solid black; border-radius:4px; box-shadow:2px 2px 5px #444444;
}
INPUT[type='text']:focus
{
font-family:monospace; background:white;
font-size:13pt; border:2px solid blue; text-align:center; font-weight:bold;
border-radius:4px; box-shadow:2px 2px 5px #444444;
}
TD
{text-align:center; line-height:150%; background:white; color:black; padding:8px;}
PRE, TEXTAREA
{
background:white; color:black; font-family:monospace; font-size:11pt;
font-weight:bold; text-align:left; line-height:125%; padding:6px;
border:4px solid black; border-radius:8px; box-shadow:2px 2px 5px #444444;
page-break-before:page;
}
INPUT[type='submit']:hover
{background:GreenYellow; box-shadow:2px 2px 5px #444444; border-radius:4px;}
</style>
</head>
<body style='background:black;'>
<table width="$TWidth" align='left'>
<tr><td style='color:white; background:#000066; border:2px solid white;
border-radius:8px 8px 0px 0px;'>
<span style='font-size:16pt;'>Long-Term Signed Julian Day Number Calculator</span><br>
<span style='font-size:11pt;'>Span: BC 20000 to AD 20000</span><br>
<span style='font-size:9pt;'>PHP Program by Jay Tanner - $cYear</span>
</td></tr>
</table>
<form name="Form1" method="post" action="">
<table bgcolor="black" align="top" border="0" cellspacing="1" width="$TWidth">
<tr><td width="25%" title=' Era: BC or AD (Default) '>Era<br>
<input name="StartBCAD" type="text" size="3" maxlength="2" value="$StartBCAD" style='font-family:monospace; font-size:11pt;'></td>
<td width="25%" title=' Year: 00001 to 20000 '>Year #<br>
<input name="StartYear" type="text" size="6" maxlength="5" value="$StartYear" style='font-family:monospace; font-size:11pt;'></td>
<td width="25%" title=' Month # (1 to 12) ' >Month #<br>
<input name="StartMonth" type="text" size="3" maxlength="2" value="$StartMonth" style='font-family:monospace; font-size:11pt;'></td>
<td width="25%" title=' Day # ( 1 to 31) ' >Day #<br>
<input name="StartDay" type="text" size="3" maxlength="2" value="$StartDay" style='font-family:monospace; font-size:11pt;'></td>
</tr></table>
<table width="$TWidth">
<tr><td style='text-align:center; line-height:200%;'><input name="SubmitButton" type="submit" value="S U B M I T"><br>
<br><b><a href="View-Source-Code.php" target="_blank"
style='font-family:Verdana; color:black; background:yellow;
text-decoration:none; border:1px solid black; padding:4px;
border-radius:4px; box-shadow:2px 2px 5px #444444;
font-weight:normal;'>
View/Copy Source Code </a></b>
</td></tr>
</table>
<table align="top" border="0" width="$TWidth">
<tr><td colspan="5">
<pre style='text-align:left;'>
$OutputJ
$OutputG
</pre></td></tr>
<tr><td colspan="5" style='background:LightYellow;'>
The Julian Day Number numerically equates to the Julian Date at 12:00:00 Noon<br>and is always a signed integer value.
<pre>
Mathematical Calendar Origins:
BC 4713-Jan-01-Mon 12:00:00 = Origin date of Julian Calendar JDNum = 0
BC 4714-Nov-24-Mon 12:00:00 = Origin date of Gregorian Calendar JDNum = 0
Julian Day Number = floor(Julian Date + 0.5)
For the calendar day of the week index (DoW = 0 to 6):
DoW = (7 + (JDNum + 1) mod 7) mod 7
Where DoW : 0=Sun, 1=Mon, 2=Tue, 3=Wed, 4=Thu, 5=Fri, 6=Sat
Applies equally to either calendar system.
</pre>
</td></tr></table>
</form>
<div style='color:GreenYellow; font-size:10pt; text-align:center; width:700px; line-height:150%;'><br>
<span style='font-size:10pt;'>Double-Click Within Text Area to Select ALL Code</span></div>
<textarea cols="79" rows="73" ReadOnly style='border:4px solid red;' OnDblClick='this.select();' OnMouseUp='return true;'>
/*
This PHP function computes the signed Julian Day Number on the old
Julian or the modern Gregorian calendar system.
It also handles proleptic dates prior to the mathematical origin of
either calendar system and can handle negative Julian Day numbers
outside the range of the native built-in PHP JD number functions.
This generic function does NOT check for invalid dates except to see
if the ('Yyyyy/mm/dd') date arguments are all numeric values.
ARGUMENTS:
Input argument strings use the format:
YmdString = 'Yyyyy/mm/dd' (Examples: '-01949/05/20' or '1949/5/20')
Yyyyy = Signed calendar year number <> 0
-Negative = BC and +Positive = AD
Span: BC 20000 to AD 20000
There is no calendar year 0 (zero).
m = Month number (1 to 12).
d = Day number (1 to 31).
JorG = Calendar mode switch.
'J' = Julian calendar
or 'G' = Gregorian calendar = Default
ERRORS:
Returns error message if any of the ('Yyyyy/mm/dd')
arguments are non-numeric.
NO EXTERNAL DEPENDENCIES
*/
function JD_Number (\$YmdString, \$JorG='G')
{
\$YmdString = trim(\$YmdString);
list(\$Y,\$m,\$d) = PReg_Split("[\/]", \$YmdString);
\$Y = trim(\$Y); \$m = trim(\$m); \$d = trim(\$d);
// Error if any of the (Y, m, d) elements are non-numeric.
if (!Is_Numeric(\$Y) or !Is_Numeric(\$m) or !Is_Numeric(\$d))
{return "ERROR: Non-Numeric Date Element(s).";}
// Get calendar mode argument (Default = 'G').
\$JorG = (StrToUpper(substr(trim(\$JorG),0,1)) == 'J')? 'J' : 'G';
// Compute JD number according to the Julian calendar.
\$A = floor((14-\$m) / 12);
\$B = ((\$Y < 0)? \$Y+1 : \$Y) - \$A;
\$C = floor(\$B/100);
\$JDNum = floor(30.6001*(12*\$A + \$m+1))+floor(365.25*(\$B+4716))-1524 + \$d;
// If the computation is for the Julian calendar, then we
// are done. Return the JD number for the Julian calendar.
if (\$JorG == 'J') {return \$JDNum;}
/* Otherwise, apply this adjustment to convert the JD number on the
old Julian calendar into the JD number for our Gregorian calendar.
This adjustment may equate to a negative or positive value and is
the difference in days between the two calendar systems on the same
given date in the context: DiffDays = (GregJDNum − JulJDNum).
*/
\$w = floor((((\$Y < 0)? \$Y+1 : \$Y) - floor((14-\$m)/12)) / 100);
\$JDNum += (floor(\$w/4) - \$w + 2);
return \$JDNum;
} // END of JD_Number (...)
</textarea>
<br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br>
</body>
</HTML>
END_OF_HTML_PAGE;
/*
This PHP function computes the signed Julian Day Number
on the old Julian or the modern Gregorian calendar system.
It also handles proleptic dates prior to the mathematical
origin of either calendar system and can handle negative
Julian Day numbers.
ARGUMENTS:
Y = Signed calendar year number <> 0
-Negative = BC and +Positive = AD
There is no calendar year 0 (zero).
m = Month number (1 to 12).
d = Day number (1 to 31).
JorG = Calendar mode switch.
'J' = Julian calendar
or 'G' = Gregorian calendar = Default
ERRORS:
Returns FALSE if any of the (Y,m,d) arguments are non-numeric.
NO EXTERNAL DEPENDENCIES
*/
function JD_Number ($YmdString, $JorG='G')
{
$YmdString = trim($YmdString);
list($Y,$m,$d) = PReg_Split("[\/]", $YmdString);
$Y = trim($Y); $m = trim($m); $d = trim($d);
// -------------------------------------------------------
// Error if any of the (Y, m, d) elements are non-numeric.
// exit("Y = $Y");
if (
!Is_Numeric($Y)
or !Is_Numeric($m)
or !Is_Numeric($d)
)
{return "ERROR: Bad Date Element(s).";}
// ---------------------------------------------------
// Compute JD number according to the Julian calendar.
$A = floor((14-$m) / 12);
$B = (($Y < 0)? $Y+1 : $Y) - $A;
$C = floor($B/100);
$JDNum = floor(30.6001*(12*$A + $m+1))+floor(365.25*($B+4716))-1524 + $d;
// If the computation is for the Julian calendar, then we
// are done. Return the JD number for the Julian calendar.
if ($JorG == 'J') {return $JDNum;}
/* Otherwise, apply this correction to convert the JD number on the
old Julian calendar into the JD number for our Gregorian calendar.
This correction may equate to a negative or positive value and is
the difference in days between the two calendar systems on the same
given date in the context: DiffDays = (GregJDNum - JulJDNum).
*/
$w = floor(((($Y < 0)? $Y+1 : $Y) - floor((14-$m)/12)) / 100);
$JDNum += (floor($w/4) - $w + 2);
return $JDNum;
}
?>