W3docs

unixtojd()

In this article, we will explore how to convert a Unix timestamp to a Julian date in PHP. Unix timestamps represent the number of seconds that have elapsed

Converting a Unix Timestamp to a Julian Day in PHP

PHP's unixtojd() function converts a Unix timestamp into a Julian Day count — a single integer that counts the number of days since the start of the Julian Period (January 1, 4713 BCE in the proleptic Julian calendar). This page explains what the function returns, how to call it, the cases where it differs from your intuition, and how to convert back the other way.

A Unix timestamp is the number of seconds elapsed since January 1, 1970, 00:00:00 UTC. A Julian Day Number (JDN) is a continuous day count widely used in astronomy and in calendar math because the difference between two Julian Days is simply the number of days between them — no month or leap-year arithmetic required. Note that the "Julian Day" here is not the same as a date in the historical Julian calendar; it is a running tally of days.

How unixtojd() Works

unixtojd() takes the integer number of seconds in a Unix timestamp, divides it down to whole days, and adds the Julian Day Number of the Unix epoch (1970-01-01), which is 2440588. The conversion is done in UTC and the result has day-level granularity — the hours, minutes, and seconds in the timestamp are discarded, so every moment within the same UTC day maps to the same Julian Day.

unixtojd() is part of PHP's Calendar extension. It is compiled in by default on most builds, but on a minimal PHP install you may need to enable the calendar extension before the function is available.

Syntax

unixtojd(?int $timestamp = null): int|false
  • $timestamp — The Unix timestamp to convert. If omitted (or null), the current time is used, exactly as if you had passed time().
  • Returns an integer Julian Day Number, or false if the timestamp could not be converted.

Basic Example

Convert the current Unix timestamp to a Julian Day:

php— editable, runs on the server

This prints the current Unix timestamp and the corresponding Julian Day Number.

Known Reference Points

Because the conversion is fixed, a few timestamps always produce the same Julian Day. These are handy for sanity-checking your code:

<?php

echo unixtojd(0), "\n";                          // 2440588  -> 1970-01-01 (the Unix epoch)
echo unixtojd(mktime(0, 0, 0, 1, 1, 2000)), "\n"; // 2451545  -> 2000-01-01
echo unixtojd(mktime(0, 0, 0, 7, 4, 2025)), "\n"; // 2460861  -> 2025-07-04

Calling It Without an Argument

Passing no argument is equivalent to passing time(), so both lines below return the same value:

<?php

echo unixtojd(), "\n";        // current day, no timestamp needed
echo unixtojd(time()), "\n";  // identical result

Converting Back: jdtounix()

The inverse of unixtojd() is jdtounix(), which turns a Julian Day Number back into a Unix timestamp set to midnight UTC of that day. Because unixtojd() throws away the time-of-day, a round trip lands you at the start of the day rather than the original moment:

<?php

$start = mktime(15, 30, 0, 7, 4, 2025); // 2025-07-04 15:30:00
$jd    = unixtojd($start);
$back  = jdtounix($jd);

echo "Original: ", gmdate("Y-m-d H:i:s", $start), " UTC\n"; // 2025-07-04 15:30:00 UTC
echo "Back:     ", gmdate("Y-m-d H:i:s", $back),  " UTC\n"; // 2025-07-04 00:00:00 UTC

When Would I Use This?

Julian Day Numbers shine whenever you need to count whole days between two dates without month-length and leap-year headaches: astronomical calculations, scheduling logic, "days until" counters, and interoperating with scientific datasets that store dates as Julian Days. For ordinary date formatting and arithmetic, the DateTime API and date functions are usually the better fit.

Conclusion

unixtojd() converts a Unix timestamp into a Julian Day Number — a day-level UTC count rooted at the epoch value 2440588. It defaults to the current time when called without an argument, ignores the time-of-day portion, and is reversed by jdtounix(). Combine it with mktime() and time() to convert any moment into a Julian Day for day-based calculations.

Practice

Practice
What is the purpose of the unixtojd() function in PHP?
What is the purpose of the unixtojd() function in PHP?
Was this page helpful?