gregoriantojd
int gregoriantojd(int month, int day, int year)
|
month
|
Gregorian calendar month number
|
|
day
|
Gregorian calendar day of month
|
|
year
|
Gregorian calendar year
|
Converts a Gregorian date to a Julian day count.
Returns:
Julian day count; 0 if any parameter is outside the valid range
Description:
gregoriantojd() converts a Gregorian calendar date to a Julian day count. If any parameter is set to a value outside of the acceptable range, the function returns 0.
The following table shows the acceptable ranges for the parameters of this function.
|
month
|
1 to 12
|
|
day
|
1 to 31
|
|
year
|
-4714 to at least 10000
|
To specify a B.C. date, use a negative value for the year
parameter.
This function is fairly forgiving in one way. If the date specified is invalid for the month specified, but still falls between 1 and 31, the function returns a valid Julian day count. The count is for the month after the specified month, with the day of the month set to the specified day minus the actual number of days in the specified month. Try the following example:
$jd = gregoriantojd (2, 31, 2002);
echo jdtogregorian ($jd);
Output:
3/3/2002
Note:
The Gregorian calendar has been in use for much of the western world for the last four centuries. It's basically the Julian calendar, with the slight modification that centennial years are not leap years (unless they are evenly divisible by 400).
Version:
3+, 4+
See also:
To convert a Julian day count to a Gregorian calendar date:
jdtogregorian()
To convert a Julian day count to another calendar system, see the other jdto* functions.
Examples:
Display the number of days left until Christmas
// Parse the current month, day, and year out of a call to date ()
list ($month, $day, $year) = explode ('/', date ('m/d/Y'));
echo gregoriantojd (12, 25, $year) - gregoriantojd ($month, $day, $year);
Demonstrate how gregoriantojd() handles invalid month days
// Get a Julian day count for February 30th, 2003
$julian_day = gregoriantojd (2, 30, 2003);
echo "The Julian day count for February 30, 2003 is $julian_day.<br />";
// Find the proper date for $julian_day
// Parse the date in separate values for $year and $day.
// Discard the month data.
list (, $day, $year) = explode ('/', jdtogregorian ($julian_day));
// Find the month name for $julian_day
$month_name = jdmonthname ($julian_day, 1);
echo "However, the proper date for this Julian day count is
actually $month_name $day, $year.";
|