Here are two methods for returning the Julian Day in SQLite.
The Julian Day is the fractional number of days since noon in Greenwich on November 24, 4714 B.C. It’s the continuous count of days since the beginning of the Julian period, and is used primarily by astronomers, and in software for easily calculating elapsed days between two events.
Option 1: The JulianDay()
Function
The JulianDay()
function is designed specifically for returning the Julian Day based on a given date. Therefore, we can do the following:
SELECT JulianDay('now');
Result:
2459648.53799336
The return value is numeric.
Option 2: The StrfTime()
Function
The StrfTime()
function can also be used for returning the Julian Day:
SELECT StrfTime('%J', 'now');
Result:
2459648.541693287
This function returns a text representation of the numeric value.
Combined
Here are the functions combined into a single SELECT
statement:
SELECT
JulianDay('now') AS JulianDay,
StrfTime('%J', 'now') AS StrfTime;
Result:
JulianDay StrfTime ---------------- ----------------- 2459648.54331729 2459648.543317292