PhpDig.net

What is PhpDig?
PhpDig is a PHP MySQL based
Web Spider & Search Engine.




gregoriantojd

Name

gregoriantojd — Converts a Gregorian date to a Julian day count.

Synopsis

int gregoriantojd(month, day, year);
int month: Gregorian calendar month number
int day: Gregorian calendar day of month
int year: Gregorian calendar year

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.

Parameter Acceptable Range of Values
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.

Note

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

PHP 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

Example

Example 71. 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);

Example 72. 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.";



PHP Functions Essential Reference. Copyright © 2002 by New Riders Publishing (Authors: Zak Greant, Graeme Merrall, Torben Wilson, Brett Michlitsch). This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at http://www.opencontent.org/openpub/). The authors of this book have elected not to choose any options under the OPL. This online book was obtained from http://www.fooassociates.com/phpfer/ and is designed to provide information about the PHP programming language, focusing on PHP version 4.0.4 for the most part. The information is provided on an as-is basis, and no warranty or fitness is implied. All persons and entities shall have neither liability nor responsibility to any person or entity with respect to any loss or damage arising from the information contained in this book.

Powered by: vBulletin Version 3.0.7
Copyright ©2000 - 2005, Jelsoft Enterprises Ltd.
Copyright © 2001 - 2005, ThinkDing LLC. All Rights Reserved.