PHP jdtounix() — Convert a Julian Day to a Unix Timestamp
Learn how PHP's jdtounix() function converts a Julian Day Count into a Unix timestamp, with syntax, working examples, valid date range, and how it pairs with gregoriantojd() and date().
The jdtounix() function converts a Julian Day Count into a Unix timestamp. It belongs to PHP's calendar extension and is the bridge between calendar-style date math (which works in whole days) and the second-based time used by the rest of PHP's date functions.
This page explains what each of those two number systems is, shows jdtounix() in action, covers its valid range and gotchas, and ends with the wider Unix-timestamp conversions you will reach for far more often (date() and strtotime()).
Two ways of counting time
Before using jdtounix(), it helps to know exactly what it converts between.
A Unix timestamp is the number of seconds elapsed since 1970-01-01 00:00:00 UTC (the "Unix epoch"). It is the standard PHP uses everywhere — time(), date(), strtotime() and DateTime all speak in Unix timestamps.
A Julian Day Count (JDC) is the number of whole days elapsed since noon on January 1, 4713 BC (in the proleptic Julian calendar). Astronomers and calendar libraries use it because it gives every day a single integer, making it trivial to count days between dates across different calendar systems. PHP's gregoriantojd(), jdtogregorian(), and friends produce and consume these counts.
jdtounix() translates a JDC into the equivalent Unix timestamp at midnight UTC of that day.
Syntax
jdtounix(int $julian_day): int$julian_day— the Julian Day Count to convert.- Returns the matching Unix timestamp. The day must fall within the supported range; an out-of-range value throws a
ValueErrorin PHP 8.0+ (older versions returnedfalse).
Basic example
You rarely have a Julian Day number lying around, so the usual flow is: turn a Gregorian date into a JDC with gregoriantojd(), then hand that to jdtounix().
<?php
// Build the Julian Day Count for 15 February 2022 (month, day, year).
$jd = gregoriantojd(2, 15, 2022);
echo $jd, "\n"; // 2459626
// Convert that day to a Unix timestamp (midnight UTC).
$timestamp = jdtounix($jd);
echo $timestamp, "\n"; // 1644883200
// Confirm by formatting it back to a readable date.
echo gmdate('Y-m-d H:i:s', $timestamp); // 2022-02-15 00:00:00Because a Julian Day represents an entire day rather than a moment, jdtounix() always returns the timestamp for 00:00:00 UTC of that day. The time-of-day information is simply not part of the input.
Valid range
jdtounix() only works within the Unix epoch's window. The lowest day it accepts is 1970-01-01, which maps to timestamp 0:
<?php
// 1 January 1970 is the lowest day jdtounix() can represent.
var_dump(jdtounix(gregoriantojd(1, 1, 1970))); // int(0)Passing a day before the epoch is an error: in PHP 8.0 and newer it throws a ValueError, while PHP 7 returned false. If the input day is user-supplied, validate the range (or wrap the call in a try/catch) before relying on the result. On systems where timestamps are stored as signed 32-bit integers, the practical upper bound is in the year 2038.
The inverse function is unixtojd(), which turns a Unix timestamp back into a Julian Day Count.
Converting a Unix timestamp to a readable date
Once you have a timestamp — from jdtounix(), time(), or a database — you format it for humans with the date() function. It takes a format string and a timestamp:
The backslashes in \a\t escape the letters a and t so they print literally instead of being read as format characters. Some of the most common format characters are:
Y— four-digit yearm— month with leading zeros (01–12)M— month abbreviation (Jan–Dec)d— day of the month with leading zeros (01–31)D— weekday abbreviation (Sun–Sat)g— hour, 12-hour format, no leading zero (1–12)H— hour, 24-hour format with leading zeros (00–23)i— minutes with leading zeros (00–59)s— seconds with leading zeros (00–59)a— lowercaseam/pm
A note on timezones
PHP formats every timestamp relative to the script's default timezone, so the same timestamp can print as different clock times on different servers. Set the timezone explicitly at the top of your script — with date_default_timezone_set() as above — so results are reproducible everywhere. The examples on this page use UTC.
Converting a readable date to a Unix timestamp
Going the other way, strtotime() parses an English date description into a Unix timestamp:
<?php
date_default_timezone_set('UTC');
$timestamp = strtotime('February 15, 2022 6:17 pm');
echo $timestamp; // 1644949020strtotime() understands many formats — 2022-02-15, next Friday, +1 week — but it is strict about wording. Filler words such as at are not allowed: strtotime('February 15, 2022 at 6:17 pm') returns false. When parsing fails, strtotime() returns false, so validate its result before using it.
When would I use jdtounix()?
For everyday "store and display a date" work, reach for date(), strtotime(), and DateTime — they handle real calendar dates and times directly. Use jdtounix() (with gregoriantojd()) when you are already working with Julian Day numbers, for example when integrating with astronomical data, interoperating with another calendar system, or counting whole days between dates and then needing a standard timestamp back.
Conversion at a glance
graph LR;
A[Gregorian date] -->|gregoriantojd| B[Julian Day Count];
B -->|jdtounix| C[Unix timestamp];
C -->|unixtojd| B;
C -->|date| D[Readable string];Conclusion
jdtounix() converts a Julian Day Count into the Unix timestamp for midnight UTC of that day, returning false for days outside the epoch range. It pairs naturally with gregoriantojd() on the way in and unixtojd() for the reverse trip. For ordinary date handling, the broader toolkit in PHP Date and Time — especially date() and strtotime() — is what you will use most.