Richard Smith
Richard Smith

Reputation: 3465

Julian day from DateTime

Is there a better way of converting a DateTime object to a Julian day number than something like this:

$jd = GregorianToJD( $dt->format('n'), $dt->format('j'), $dt->format('Y') );

I'm a bit surprised there isn't either a function to do it directly or a format specifier to print it. Am I missing something obvious?

Edit: Many of the (somewhat sarcastic) replies below seem to be assuming the Julian day number is somehow related to the long-obsolete Julian calendar. It isn't. The Julian day number is one of the most common ways of numbering days from a fairly arbitrary epoch. Its main use is in astronomy where it is the standard way of identifying a date.

Upvotes: 9

Views: 4908

Answers (1)

moorscode
moorscode

Reputation: 801

This should do the trick:

// $dt = new DateTime();
$jd = unixtojd( $dt->getTimestamp());

See more on unixtojd on PHP.net

Upvotes: 6

Related Questions