Julian Date Developer Reference
Tested, copy-paste-ready snippets for computing the Julian date and day-of-year in eleven languages and databases. Every example is written for UTC output so it agrees with this site. As of Thursday, June 18, 2026, the day of year is 169.
Conventions used in every snippet
"Julian date" covers two unrelated families of values. These snippets produce both. The ordinal codes (DOY, YJJJ, YYDDD, YYYYDDD) describe a calendar day; the astronomical counts (JDN, JD, MJD) describe a continuous timeline. See the seven formats for the full breakdown.
- Day of year (DOY) is 1-based: January 1 = 1, December 31 = 365 (or 366 in a leap year).
- YJJJ / YYDDD / YYYYDDD prepend 1, 2, or 4 year digits to the zero-padded 3-digit day of year.
- JDN is the integer Julian Day Number, referenced to noon UTC.
- JD at civil midnight ends in .5 because the JD day starts at noon. MJD = JD − 2,400,000.5.
- All integer JDN formulas are Fliegel & Van Flandern (1968) — the same algorithm used by the U.S. Naval Observatory.
| Value | Today (UTC) |
|---|---|
| Day of year | 169 |
| 4-digit YJJJ | 6169 |
| 5-digit YYDDD | 26169 |
| 7-digit YYYYDDD | 2026169 |
| Julian Day Number | 2461210 |
| Julian Date | 2461210.25335 |
| Modified Julian Date | 61209.75335 |
Python
The standard library covers day-of-year directly. Use an explicit UTC clock instead of the host timezone, and the Fliegel–Van Flandern formula for the Julian Day Number.
Python
from datetime import datetime, timezone
today = datetime.now(timezone.utc).date()
doy = today.timetuple().tm_yday # 1..366
yjjj = f"{today.year % 10}{doy:03d}" # 4-digit YJJJ
yyddd = f"{today.year % 100:02d}{doy:03d}" # 5-digit YYDDD
yyyyddd = f"{today.year}{doy:03d}" # 7-digit YYYYDDD
# Julian Day Number (integer, noon UTC) — Fliegel & Van Flandern, 1968
def jdn(y, m, d):
a = (14 - m) // 12
y2 = y + 4800 - a
m2 = m + 12 * a - 3
return (d + (153 * m2 + 2) // 5 + 365 * y2
+ y2 // 4 - y2 // 100 + y2 // 400 - 32045)
# Astronomical Julian Date (fractional) and Modified Julian Date
def jd(dt):
secs = dt.hour * 3600 + dt.minute * 60 + dt.second + dt.microsecond / 1e6
return jdn(dt.year, dt.month, dt.day) + (secs / 86400.0) - 0.5
n = datetime.now(timezone.utc)
print(doy, yjjj, yyddd, yyyyddd, jdn(n.year, n.month, n.day),
f"{jd(n):.5f}", f"{jd(n) - 2400000.5:.5f}") JavaScript
Dependency-free, runs in any modern browser or Node. JD is anchored to the Unix epoch (JD 2440587.5 = 1970-01-01 00:00 UTC).
JavaScript
function dayOfYear(d = new Date()) {
const start = Date.UTC(d.getUTCFullYear(), 0, 0);
const now = Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate());
return Math.floor((now - start) / 86400000); // 1..366
}
function ordinalCodes(d = new Date()) {
const y = d.getUTCFullYear();
const j = String(dayOfYear(d)).padStart(3, '0');
return {
yjjj: `${y % 10}${j}`,
yyddd: `${String(y % 100).padStart(2, '0')}${j}`,
yyyyddd: `${y}${j}`,
};
}
// Astronomical counts. Date.now() is ms since the Unix epoch.
const jd = (d = new Date()) => d.getTime() / 86400000 + 2440587.5;
const jdn = (d = new Date()) => Math.floor(jd(d) + 0.5);
const mjd = (d = new Date()) => jd(d) - 2400000.5;
console.log(dayOfYear(), ordinalCodes(), jdn(), jd().toFixed(5), mjd().toFixed(5)); SQL — PostgreSQL
Postgres has native Julian Day Number support via the J format mask in to_char. Force a UTC timestamp first so results match this site.
SQL — PostgreSQL
-- Work from an explicit UTC date
WITH d AS (SELECT (now() AT TIME ZONE 'UTC')::date AS dt)
SELECT
EXTRACT(DOY FROM dt)::int AS doy, -- 1..366
to_char(dt, 'FMYYDDD') AS yyddd, -- 5-digit
to_char(dt, 'FMYYYYDDD') AS yyyyddd, -- 7-digit
to_char(dt, 'J')::bigint AS jdn -- Julian Day Number
FROM d;
-- 4-digit YJJJ (single year digit) has no direct mask:
WITH d AS (SELECT (now() AT TIME ZONE 'UTC')::date AS dt)
SELECT (EXTRACT(YEAR FROM dt)::int % 10)
|| to_char(dt, 'DDD') AS yjjj
FROM d; SQL — MySQL / MariaDB
No native JDN function, but TO_DAYS plus a constant offset reproduces it. UTC_DATE() avoids session-timezone drift.
SQL — MySQL / MariaDB
SELECT
DAYOFYEAR(UTC_DATE()) AS doy, -- 1..366
CONCAT(MOD(YEAR(UTC_DATE()), 10),
LPAD(DAYOFYEAR(UTC_DATE()), 3, '0')) AS yjjj, -- 4-digit
DATE_FORMAT(UTC_DATE(), '%y%j') AS yyddd, -- 5-digit
DATE_FORMAT(UTC_DATE(), '%Y%j') AS yyyyddd, -- 7-digit
TO_DAYS(UTC_DATE()) + 1721060 AS jdn; -- Julian Day Number
-- Note: MySQL's %j is already zero-padded to 3 digits. SQL — SQL Server (T-SQL)
T-SQL has no JDN mask; derive it with DATEDIFF from a known JDN anchor (1970-01-01 = JDN 2440588). FORMAT uses .NET tokens, where ddd is day-of-year.
SQL — SQL Server (T-SQL)
DECLARE @d date = CAST(GETUTCDATE() AS date);
SELECT
DATEPART(dayofyear, @d) AS doy, -- 1..366
CONCAT(YEAR(@d) % 10, FORMAT(@d, 'ddd')) AS yjjj, -- 4-digit
FORMAT(@d, 'yyddd') AS yyddd, -- 5-digit
FORMAT(@d, 'yyyyddd') AS yyyyddd, -- 7-digit
DATEDIFF(day, '1970-01-01', @d) + 2440588 AS jdn; -- Julian Day Number SQL — Oracle
Oracle's J format mask returns the Julian Day Number directly. SYS_EXTRACT_UTC normalizes to UTC before casting to DATE.
SQL — Oracle
SELECT
TO_CHAR(d, 'DDD') AS doy, -- 1..366
TO_CHAR(MOD(EXTRACT(YEAR FROM d), 10)) || TO_CHAR(d, 'DDD') AS yjjj,
TO_CHAR(d, 'YYDDD') AS yyddd, -- 5-digit
TO_CHAR(d, 'YYYYDDD') AS yyyyddd, -- 7-digit
TO_CHAR(d, 'J') AS jdn -- Julian Day Number
FROM (
SELECT CAST(SYS_EXTRACT_UTC(SYSTIMESTAMP) AS DATE) AS d FROM dual
); Excel / Google Sheets
Spreadsheet serial dates start at 1900-01-01 = serial 1, so JD = serial + 2415018.5 and MJD = serial + 15018. TODAY() follows the workbook/account timezone — set it to UTC for exact agreement.
Excel / Google Sheets
Day of year: =TODAY()-DATE(YEAR(TODAY()),1,0)
YJJJ (4-digit): =MOD(YEAR(TODAY()),10)&TEXT(TODAY()-DATE(YEAR(TODAY()),1,0),"000")
YYDDD: =TEXT(TODAY(),"yy")&TEXT(TODAY()-DATE(YEAR(TODAY()),1,0),"000")
YYYYDDD: =TEXT(YEAR(TODAY()),"0000")&TEXT(TODAY()-DATE(YEAR(TODAY()),1,0),"000")
JDN (integer): =INT(TODAY()+2415018.5)
JD (midnight): =TODAY()+2415018.5
MJD: =TODAY()+15018 Go
time.YearDay() gives the ordinal day directly. The JDN here uses the same Fliegel–Van Flandern integer formula.
Go
package main
import (
"fmt"
"time"
)
func jdn(t time.Time) int {
y, m, d := t.Year(), int(t.Month()), t.Day()
a := (14 - m) / 12
y2 := y + 4800 - a
m2 := m + 12*a - 3
return d + (153*m2+2)/5 + 365*y2 + y2/4 - y2/100 + y2/400 - 32045
}
func main() {
t := time.Now().UTC()
doy := t.YearDay() // 1..366
fmt.Printf("doy=%d yjjj=%d%03d yyddd=%02d%03d yyyyddd=%d%03d jdn=%d
",
doy, t.Year()%10, doy, t.Year()%100, doy, t.Year(), doy, jdn(t))
} Rust (chrono)
The chrono crate exposes ordinal() for day-of-year and a NaiveDate::to_julian_day() helper for the Julian Day Number. Add chrono = "0.4" to Cargo.toml.
Rust (chrono)
use chrono::{Datelike, Utc};
fn main() {
let t = Utc::now();
let doy = t.ordinal(); // 1..366
let jdn = t.date_naive().num_days_from_ce() + 1_721_425; // CE day 1 = JDN 1721426
println!("doy={doy}");
println!("yjjj={}{:03}", t.year() % 10, doy);
println!("yyddd={:02}{:03}", t.year() % 100, doy);
println!("yyyyddd={}{:03}", t.year(), doy);
println!("jdn={jdn}");
} C#
DateTime.DayOfYear is 1-based. The JDN uses the Fliegel–Van Flandern formula; use DateTime.UtcNow to avoid local-time drift.
C#
using System;
static long Jdn(DateTime t) {
int y = t.Year, m = t.Month, d = t.Day;
int a = (14 - m) / 12;
int y2 = y + 4800 - a;
int m2 = m + 12 * a - 3;
return d + (153 * m2 + 2) / 5 + 365L * y2 + y2 / 4 - y2 / 100 + y2 / 400 - 32045;
}
var t = DateTime.UtcNow;
int doy = t.DayOfYear; // 1..366
Console.WriteLine($"yjjj={t.Year % 10}{doy:D3}");
Console.WriteLine($"yyddd={t.Year % 100:D2}{doy:D3}");
Console.WriteLine($"yyyyddd={t.Year}{doy:D3}");
Console.WriteLine($"jdn={Jdn(t)}"); Bash (GNU coreutils)
GNU date emits ordinal formats natively. The -u flag forces UTC. JDN is computed by reusing date as a calculator.
Bash (GNU coreutils)
date -u +%j # day of year (zero-padded, 001..366)
echo "$(($(date -u +%Y)%10))$(date -u +%j)" # 4-digit YJJJ
date -u +%y%j # 5-digit YYDDD
date -u +%Y%j # 7-digit YYYYDDD
# Julian Day Number via the days-since-epoch trick (1970-01-01 = JDN 2440588)
echo $(( $(date -u -d "$(date -u +%F)" +%s) / 86400 + 2440588 )) PHP
PHP's date('z') is 0-based (Jan 1 = 0), so add 1 for a standard day-of-year. The intl-free gregoriantojd() returns the Julian Day Number directly.
PHP
<?php
date_default_timezone_set('UTC');
$doy = (int) date('z') + 1; // 1..366 (date('z') is 0-based)
echo $doy, "\n";
echo sprintf('%d%03d', date('y') % 10, $doy), "\n"; // 4-digit YJJJ
echo sprintf('%02d%03d', date('y'), $doy), "\n"; // 5-digit YYDDD
echo sprintf('%04d%03d', date('Y'), $doy), "\n"; // 7-digit YYYYDDD
echo gregoriantojd((int) date('n'), (int) date('j'), (int) date('Y')), "\n"; // JDN Which algorithm are these based on?
Every integer Julian Day Number above uses the canonical Fliegel & Van Flandern formula (1968), the same algorithm documented by the U.S. Naval Observatory and in Jean Meeus's Astronomical Algorithms, chapter 7. The day-of-year computation is plain ordinal date arithmetic. For databases and runtimes with a configurable session timezone, you must select UTC explicitly to get exact agreement with the values shown on this page.
Need to verify a single value or reverse a code back to a date? Use the converter. For decoding the codes stamped on products, see the batch decoder and the guide to Julian dates in manufacturing.
Convert any date →
Get every Julian format for any calendar date, or reverse a code back to a date.
See all seven formats →
DOY, YJJJ, YYDDD, YYYYDDD, JDN, JD, and MJD — who uses each and why.