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.
This should do the trick:
// $dt = new DateTime();
$jd = unixtojd( $dt->getTimestamp());
See more on unixtojd on PHP.net
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With