frenchtojd()
Before we dive into the nitty-gritty details of French-to-Julian day conversion in PHP, let's start with a brief introduction. Julian day is the continuous
Introduction
PHP's frenchtojd() function converts a date in the French Republican calendar into a Julian Day Count — a single integer that uniquely identifies a calendar day. This page explains what those two terms mean, how to call the function, what its return values mean, and the edge cases that trip people up.
A Julian Day Count (JDC) is the continuous count of days since the start of the Julian period: noon UTC on January 1, 4713 BC. Because it is a plain integer, it is the common "pivot" format PHP uses to convert between calendars — you convert calendar A to a Julian day, then convert that Julian day to calendar B. It is also widely used in astronomy and any field that needs continuous, calendar-independent time measurement.
The French Republican calendar was used in France from 1793 to 1805, introduced by the French Revolution to replace the Gregorian calendar. It has 12 months of 30 days each, divided into three ten-day weeks (décades), plus 5 or 6 extra "complementary days" at the end of the year. Years are counted from the founding of the Republic (Year I, Year II, …), conventionally written with Roman numerals.
Using PHP's Built-in frenchtojd() Function
To convert a French Republican date to a Julian day in PHP, call the native frenchtojd() function. PHP handles the calendar mathematics internally, so you don't implement the algorithm yourself.
Note: This function requires the calendar extension to be enabled. Check with extension_loaded('calendar'); if it returns false, enable the extension in your php.ini.
<?php
$jd = frenchtojd($month, $day, $year);
?>The function accepts three integer parameters and returns an int:
$month: The month number (1–13). Months 1–12 are the regular 30-day months (Vendémiaire … Fructidor); month 13 holds the complementary days.$day: The day of the month (1–30 for months 1–12, 1–6 for month 13).$year: The year of the French Republic, e.g.1for Year I.
The valid range is roughly 1 Vendémiaire Year 1 through the end of Year 14. Any date outside the supported range — including frenchtojd(0, 0, 0) — returns 0. Always check for a 0 result before using the value.
Example Usage
Pass the month, day, and year of the French date as parameters:
<?php
$jd = frenchtojd(12, 22, 1);
echo $jd; // Output: 2376191
?>Here we convert 22 Fructidor, Year I (month 12, day 22, year 1) to its Julian day count, 2376191. That Julian day corresponds to September 8, 1793 in the Gregorian calendar.
Round-Tripping to Other Calendars
Because the result is a Julian day, you can hand it to any jdto*() function to express the same day in another calendar. This is the most common reason to call frenchtojd():
<?php
$jd = frenchtojd(12, 22, 1); // 22 Fructidor, Year I → 2376191
echo jdtogregorian($jd), "\n"; // Output: 9/8/1793
echo jddayofweek($jd, 1), "\n"; // Output: Sunday
?>To convert back the other way, use jdtofrench(), the inverse of frenchtojd().
Common Pitfalls
- Argument order is
month, day, year— not the day-month-year order used in everyday French dates. Swapping the first two is the most frequent bug. - A
0return means "invalid or out of range," not "an error was thrown." The function does not raise an exception, so validate the result yourself. - The complementary days live in month 13, not appended to month 12. Use
frenchtojd(13, 1, $year)throughfrenchtojd(13, 6, $year)for them. - The
calendarextension is not always enabled, especially in minimal Docker images. Guard withextension_loaded('calendar')in portable code.
Related Functions
jdtofrench()— the inverse: Julian day → French Republican date.gregoriantojd()— convert a Gregorian date to a Julian day.juliantojd()— convert a Julian (proleptic) calendar date to a Julian day.jddayofweek()— get the day of the week for a Julian day.
Conclusion
frenchtojd() makes converting French Republican dates to Julian days a single function call. Remember the month, day, year argument order, treat a 0 return as "out of range," and use the resulting Julian day as a bridge to other calendars via the jdto*() family.